private void TrainModel(System.IntPtr model, double[,] values) { var nbInputs = values.GetUpperBound(0) - 1; for (int y = 0; y < values.GetUpperBound(1); y++) { double[] inputs = new double[nbInputs]; int expected = 0; for (int x = 0; x < values.GetUpperBound(0); x++) { var value = values[x, y]; if (x == nbInputs) { expected = Convert.ToInt32(value); } else { inputs[x] = value; } } PanebWrapper.classification_train(model, inputs.Length, inputs, expected); } }
private void ComputeInputs(System.IntPtr model, double[,] values) { var nbInputs = values.GetUpperBound(0) - 1; for (int y = 0; y < values.GetUpperBound(1); y++) { double[] inputs = new double[nbInputs]; int expected = 0; for (int x = 0; x < values.GetUpperBound(0); x++) { var value = values[x, y]; if (x == nbInputs) { expected = Convert.ToInt32(value); } else { inputs[x] = value; } } int result = PanebWrapper.classification_compute(model, inputs.Length, inputs); Debug.Log("Expected: " + expected + "; Result = " + result); } }
void Start() { var model = PanebWrapper.pmc_create(nbLayers, layers); TrainModel(model); MoveAxis(model); }
void Start() { var weights = PanebWrapper.classification_create(3); TrainModel(weights); MoveAxis(weights); }
private void ComputeInputs(System.IntPtr model, double[,] values) { var nbInputs = values.GetUpperBound(0) - 1; for (int y = 0; y < values.GetUpperBound(1); y++) { double[] inputs = new double[nbInputs]; double expected = 0.0; for (int x = 0; x < values.GetUpperBound(0); x++) { var value = values[x, y]; if (x == nbInputs) { expected = value; } else { inputs[x] = value; } } double result = PanebWrapper.regression_point(model, inputs.Length, inputs); Debug.Log("Expected: " + expected + "; Result = " + result); } }
private System.IntPtr CreateModel(double[,] values) { var nbInputs = values.GetUpperBound(0) - 1; var nbInputRows = values.GetUpperBound(1); var nbInputCols = values.GetUpperBound(0); double[] inputs = new double[nbInputRows * nbInputCols]; var inputIterator = 0; var nbOutputRows = values.GetUpperBound(1); var nbOutputCols = 1; double[] outputs = new double[nbOutputRows * nbOutputCols]; var outputIterator = 0; for (int y = 0; y < values.GetUpperBound(1); y++) { for (int x = 0; x < values.GetUpperBound(0); x++) { var value = values[x, y]; if (x == nbInputs) { outputs[outputIterator++] = value; } else { inputs[inputIterator++] = value; } } } return(PanebWrapper.regression_compute(nbInputRows, nbInputCols, inputs, nbOutputRows, nbOutputRows, outputs)); }
private void PrintWeights(System.IntPtr weights) { Debug.Log( PanebWrapper.classification_weights(weights, 0) + "; " + PanebWrapper.classification_weights(weights, 1) + "; " + PanebWrapper.classification_weights(weights, 2) ); }
void Start() { var inputs = ComputeInputs(); var outputs = ComputeOutputs(); var weights = PanebWrapper.regression_compute(spheres.Length, 3, inputs, spheres.Length, 1, outputs); MoveAxis(weights); }
private void MoveAxis(System.IntPtr weights) { foreach (var white in whites) { var x = white.position.x; var z = white.position.z; int direction = PanebWrapper.classification_compute(weights, 2, new double[] { x, z }); white.position += direction == 1 ? Vector3.up : Vector3.down; } }
private void MoveAxis(System.IntPtr weights) { foreach (var white in whites) { var x = white.position.x; var z = white.position.z; double result = PanebWrapper.regression_point(weights, 2, new double[] { x, z }); //Debug.Log("[" + x + ", " + z + "] = " + result); white.position += Vector3.up * (float)result; } }
private void MoveAxis(System.IntPtr model) { foreach (var white in whites) { var x = white.position.x; var z = white.position.z; System.IntPtr outputs = PanebWrapper.pmc_compute(nbLayers, layers, model, 2, new double[] { x, z }, 0); double value = PanebWrapper.pmc_value(outputs, 0); white.position += value > 0.0 ? Vector3.up : Vector3.down; } }
void Start() { string[,] csvTraining = CSVReader.SplitCsvGrid(trainingCsv.text); double[,] trainingValues = StringArrayToDouble(csvTraining); string[,] csvTest = CSVReader.SplitCsvGrid(testCsv.text); double[,] testValues = StringArrayToDouble(csvTest); var nbWeights = trainingValues.GetUpperBound(0); var model = PanebWrapper.classification_create(nbWeights); TrainModel(model, trainingValues); ComputeInputs(model, testValues); }
private void TrainModel(System.IntPtr weights) { for (int i = 0; i < 300; ++i) { foreach (var sphere in spheres) { var transform = sphere.GetComponent <Transform>(); var x = transform.position.x; var z = transform.position.z; var expected = (int)transform.position.y; PanebWrapper.classification_train(weights, 2, new double[] { x, z }, expected); } } }
private void TrainModel(System.IntPtr model) { for (int i = 0; i < 300; ++i) { foreach (var sphere in spheres) { var transform = sphere.GetComponent <Transform>(); var x = transform.position.x; var z = transform.position.z; var expected = transform.position.y; PanebWrapper.pmc_train(nbLayers, layers, model, 2, new double[] { x, z }, 1, new double[] { expected }, 0); } } }