Exemplo n.º 1
0
        public static NumDataTable LoadData(this Simulation simulation, SimInput input)
        {
            var pathToData = GetPathToData(simulation, input.Hash);

            RequireFile(pathToData);
            return(NumDataTable.LoadFromBinaryFile(pathToData));
        }
Exemplo n.º 2
0
        public static void SaveData(this Simulation simulation, NumDataTable data, SimInput input)
        {
            var pathToData = GetPathToData(simulation, input.Hash);

            if (File.Exists(pathToData))
            {
                throw new InvalidOperationException($"Expecting empty path to save data: {pathToData}");
            }

            var pathToDataDirectory = Path.GetDirectoryName(pathToData);

            RequireNotNullEmptyWhiteSpace(pathToDataDirectory);
            if (!Directory.Exists(pathToDataDirectory))
            {
                Directory.CreateDirectory(pathToDataDirectory);
            }

            NumDataTable.SaveToBinaryFile(data, pathToData);

            var edits = input.SimParameters.Filter(p =>
            {
                var search   = simulation.SimConfig.SimInput.SimParameters.Find(q => q.Name == p.Name);
                var original = search.AssertSome($"Unknown parameter {p.Name}");
                return(p.Value != original.Value);
            });

            if (!edits.IsEmpty)
            {
                var edited = simulation.SimConfig.SimInput.With(edits);
                Toml.WriteFile(edited, Path.Combine(pathToDataDirectory, EditsFileName));
            }
        }
Exemplo n.º 3
0
        internal static void SaveSensitivityDesignTrace(
            SensitivityDesign instance,
            NumDataTable trace,
            string pathToSensitivityDesignsDirectory
            )
        {
            RequireDirectory(pathToSensitivityDesignsDirectory);

            var sensitivityDesignDirectory       = instance.CreatedOn.ToDirectoryName();
            var pathToSensitivityDesignDirectory = Combine(
                pathToSensitivityDesignsDirectory,
                sensitivityDesignDirectory
                );

            RequireDirectory(pathToSensitivityDesignDirectory);

            var pathToSerializedTrace = Combine(
                pathToSensitivityDesignDirectory,
                SERIALIZED_TRACE_FILE_NAME
                );

            using var memoryStream = new MemoryStream();
            Serializer.Serialize(memoryStream, trace);
            memoryStream.Position = 0;
            File.WriteAllBytes(pathToSerializedTrace, memoryStream.ToArray());
        }
Exemplo n.º 4
0
        static Data()
        {
            var independent = Enumerable.Range(0, 9).Select(i => i * 1000.0).ToDataColumn("RPM");
            var hpPerRpm = new[] { 0.0, 24, 52, 74, 98, 112, 124, 122, 116 }.ToDataColumn("HP per RPM");
            var torquePerRpm = new[] { 0.0, 22, 45, 54, 58, 55, 50, 47, 45 }.ToDataColumn("Torque per RPM");

            HPTorqueOverRPM = new NumDataTable("HP/Torque by RPM", independent, hpPerRpm, torquePerRpm);
        }
Exemplo n.º 5
0
 internal static SimDataOutput Create(
     Simulation simulation,
     SimInput serieInput,
     NumDataTable serie,
     OutputOrigin outputOrigin,
     DateTime acquiredOn,
     bool persist
     ) =>
Exemplo n.º 6
0
        private static SymbolInfo SymbolicExpressionToSymbolInfo(
            string?name,
            SymbolicExpression symbolicExpression,
            SymbolType symbolType
            )
        {
            NumDataTable?value  = default;
            int          length = 0;

            string[]? names = default;

            try
            {
                var matrices      = SexpToMatrices(symbolicExpression, name);
                var tabulatedData = new List <NumDataColumn>();
                foreach (var(columnNames, array) in matrices)
                {
                    var numDataColumns = MatrixToNumDataColumns(
                        array,
                        columnNames
                        );
                    tabulatedData.AddRange(numDataColumns);
                }

                var isJagged = tabulatedData.NotAllSame(ndc => ndc.Length);
                if (isJagged)
                {
                    // non-output so process as input (parameters)
                    tabulatedData = tabulatedData.Where(ndc => ndc.Length == 1).ToList();
                }

                value  = new NumDataTable(name, tabulatedData);
                length = value.NColumns;
                length = length > 0 ? length * value[0].Length : length;
                names  = value.ColumnNames.ToArray();
            }
            catch (Exception) { }

            return(new SymbolInfo
            {
                Symbol = name,
                Value = value,
                SymbolType = symbolType,
                SymbolicExpressionType = (int)symbolicExpression.Type,
                Length = length,
                Names = names
            });
        }
Exemplo n.º 7
0
        public static FxDataTable ToFxDataTable(this NumDataTable rvDataTable)
        {
            var fxDataTable = new FxDataTable(rvDataTable.Name);

            rvDataTable.ColumnNames.Iter(
                cn => fxDataTable.Columns.Add(cn, typeof(double))
                );

            for (var i = 0; i < rvDataTable.NRows; ++i)
            {
                var row = rvDataTable.GetRow <object>(i);
                fxDataTable.Rows.Add(row);
            }

            return(fxDataTable);
        }
Exemplo n.º 8
0
 private SimDataOutput(
     Simulation simulation,
     SimInput serieInput,
     NumDataTable serie,
     OutputOrigin outputOrigin,
     DateTime acquiredOn,
     bool persist,
     DateTime persistedOn
     )
 {
     Simulation   = simulation;
     SerieInput   = serieInput;
     Serie        = serie;
     OutputOrigin = outputOrigin;
     AcquiredOn   = acquiredOn;
     Persist      = persist;
     PersistedOn  = persistedOn;
 }
Exemplo n.º 9
0
        public static (ValueCandidate, Arr <ValueCandidate>) CreateForExec(NumDataTable table, Arr <ISymbolInfo> symbolInfos)
        {
            RequireTrue(table.NColumns > 1);
            RequireTrue(table.NumDataColumns[0].Length > 1);

            var valueCandidates = table.NumDataColumns
                                  .Map(ndc => new ValueCandidate(ndc, symbolInfos));

            var independentVariable = valueCandidates.Head();

            independentVariable.ElementCandidates[0].IsUsed = true;
            independentVariable.ElementCandidates[0].IsIndependentVariable = true;

            valueCandidates = valueCandidates
                              .Tail()
                              .OrderBy(vc => vc.Name);

            return(independentVariable, valueCandidates.ToArr());
        }
Exemplo n.º 10
0
        public void TestSerializeDataTable()
        {
            // arrange
            var columns = new[] {
                new NumDataColumn("doubles", new[] { 1.0, 2.0, 3.0 }),
                new NumDataColumn("more doubles", new[] { 4.0, 5.0, 6.0 })
            };
            var toSerialize = new NumDataTable("test", columns);

            // act
            var memoryStream = new MemoryStream();

            Serializer.Serialize(memoryStream, toSerialize);
            memoryStream.Position = 0;
            var deserialized = Serializer.Deserialize <NumDataTable>(memoryStream);

            // assert
            Assert.AreEqual(toSerialize.Name, deserialized.Name);
            Assert.IsTrue(toSerialize[0].Data.SequenceEqual(deserialized[0].Data));
            Assert.IsTrue(toSerialize[1].Data.SequenceEqual(deserialized[1].Data));
        }
Exemplo n.º 11
0
 public static Arr <NumDataColumn> GetDependentData(this SimOutput output, NumDataTable dataTable) =>
 output.DependentVariables.Map(e => dataTable[e.Name]);
Exemplo n.º 12
0
 public static NumDataColumn GetIndependentData(this SimOutput output, NumDataTable dataTable) =>
 dataTable.NumDataColumns.Single(ndc => ndc.Name == output.IndependentVariable.Name);