void Init(ExperimentRunner unused) { SessionSetupPanel.Init(runner); previewer = new DesignPreviewer(runner.DesignFile); DisplayPreview(); }
static void CheckWindowOpen(ExperimentRunner runnerToInit) { if (IsOpen) { runnerToInit.WindowOpen = true; } }
void Init(ExperimentRunner runnerToInit) { runner = runnerToInit; currentBlockIndex = -1; currentTrialIndex = -1; started = false; }
public void RunExperimentWithConfigurationFile(string path) { Ticker.Receiver.Instance.SendMessage( methodName: "OnMessage", value: new Ticker.Message.InfoMessage(DateTime.Now.ToString() + " starting experiment with the configuration from " + path), options: SendMessageOptions.RequireReceiver ); ExperimentRunner.Configuration configuration; try { configuration = ExperimentRunner.Configuration.FromJson(path); } catch (Exception e) { Ticker.Receiver.Instance.SendMessage( methodName: "OnMessage", value: new Ticker.Message.ErrorMessage("Could not read the file " + path + "\n\t error: " + e.Message), options: SendMessageOptions.RequireReceiver ); return; } ClearScene(); ExperimentRunner experiment = ICPFragmentParent.GetComponent <ExperimentRunner>(); experiment.Init(configuration); StartCoroutine(experiment.Execute()); }
public void Init(ExperimentRunner runnerToInit) { runner = runnerToInit; session = runner.Session; if (session == null) { throw new NullReferenceException("session could not be created"); } SessionStatusText.text = "New session successfully created"; List <ParticipantVariable> participantVariables = runner.DesignFile.GetFactory.GetVariables.ParticipantVariables; ParticipantVariablePanel.ShowParticipantVariables(participantVariables); switch (runner.DesignFile.GetTrialTableGeneration) { case TrialTableGenerationMode.OnTheFly: ShowBlockOrderSettings(); break; case TrialTableGenerationMode.PreGenerated: DesignFilePanel.Show(); break; default: throw new ArgumentOutOfRangeException(); } SetSelectedBlockOrder(session.BlockOrderChosenIndex + 1); OutputFilePanel.SetupFields(session.OutputFile); }
void InitGui(ExperimentRunner experimentRunner) { gameObject.SetActive(true); int targetDisplay = experimentRunner.DesignFile.GetGuiSettings.TargetDisplay; if (Display.displays.Length > targetDisplay || Application.isEditor) { if (!Application.isEditor) { Display.displays[targetDisplay].Activate(); } Debug.Log($"{TuxLog.Prefix} Setting UI to show on Display {targetDisplay + 1}. Click here to highlight current settings file in project.", experimentRunner.DesignFile.GetGuiSettings); if (targetDisplay > 0 && experimentRunner.DesignFile.GetGuiSettings.WarnUserIfNotDisplayOne) { Debug.LogWarning(TuxLog.Warn("UI is on secondary display. If you can't see UI, adjust settings. You can turn this warning off (click on this message)."), experimentRunner.DesignFile.GetGuiSettings); } } else { Debug.LogWarning($"{TuxLog.Prefix} Not enough displays plugged in to accommodate your UI settings. Reverting UI to display on {Display.displays.Length}"); targetDisplay = Display.displays.Length; } Canvas.targetDisplay = targetDisplay; if (targetDisplay != 0) { placeholderCamera.targetDisplay = targetDisplay; } }
public void RegisterExperiment(ExperimentRunner experimentRunner) { ExperimentEvents.OnInitExperiment += Init; ExperimentEvents.OnExperimentStarted += ExperimentHasStarted; runner = experimentRunner; fileLocationSettings = runner.DesignFile.GetFileLocationSettings; InitGui(experimentRunner); }
public SimpleBlock(ExperimentRunner runner, DataTable trialTable, DataRow dataRow, int index) : base(runner, trialTable, dataRow, index) { }
public SimpleBlock(ExperimentRunner runner, DataTable trialTable, string identity, Type customTrialType) : base(runner, trialTable, identity, customTrialType) { }
void InitWindow(ExperimentRunner runnerToInit) { session = Session.LoadSessionData(); currentBlockIndex = -1; currentTrialIndex = -1; runner = runnerToInit; initialized = true; Repaint(); runnerToInit.FinishedInitialization = true; }
static ExperimentRunner CheckRunnerCreated() { if (!EditorPrefs.HasKey(RunnerKey)) { return(null); } string typeName = EditorPrefs.GetString(RunnerKey); EditorPrefs.DeleteKey(RunnerKey); // Get the new type from the reloaded assembly! // (It won’t work without assembly specification, because this // is an editor script, so the default assembly is “Assembly-CSharp-editor”) Type type = null; var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { type = assembly.GetType(typeName); if (type != null) { break; } } if (type == null) { Debug.LogError($"{TuxLog.Prefix} Cannot find runner script to create. Name: {typeName} Key: {RunnerKey}, String: {EditorPrefs.GetString(RunnerKey)}"); Debug.LogError($"{TuxLog.Prefix} Printing Verbose error report:"); Debug.LogError($"{TuxLog.Prefix}"); foreach (Assembly assembly in assemblies) { StringBuilder sb = new StringBuilder(); sb.AppendLine(assembly.ToString()); foreach (Type listedType in assembly.GetTypes()) { sb.AppendLine(listedType.ToString()); } Debug.Log($"{TuxLog.Prefix} {sb}"); } } GameObject newGameObject = new GameObject(); newGameObject.name = typeName; Debug.Log($"{TuxLog.Prefix} Creating GameObject type {type} in currently open scene"); ExperimentRunner runner = newGameObject.AddComponent(type) as ExperimentRunner; return(runner); }
static void Main(String[] args) { String buildIndexLocation = @"C:\Users\Mike\Documents\R-Tree Framework\trunk\IndexBuildsNonRSharp.csv", workPlanLocation = @"C:\Users\Mike\Documents\R-Tree Framework\trunk\WorkPlansNonRSharp.csv"; ExperimentRunner er = new ExperimentRunner(); //er.LoadBuildIndexExperiments(buildIndexLocation); //er.LoadRunWorkPlanExperiments(workPlanLocation); buildIndexLocation = @"C:\Users\Mike\Documents\R-Tree Framework\trunk\IndexBuildsNonRSharp2.csv"; workPlanLocation = @"C:\Users\Mike\Documents\R-Tree Framework\trunk\WorkPlansNonRSharp2.csv"; er.LoadBuildIndexExperiments(buildIndexLocation); er.LoadRunWorkPlanExperiments(workPlanLocation); er.RunExperiments(); }
// Update is called once per frame void FixedUpdate() { ExperimentRunner exp = GetComponent <ExperimentRunner>(); if (exp.IsStarted()) { ball_controller = GetComponent <BallController>(); OscMessage message = new OscMessage(); message.address = "/morphoses/data"; // Experiment. message.values.Add(exp.GetId()); // Time. message.values.Add((float)exp.GetTime()); // Position. message.values.Add(transform.position.x); message.values.Add(transform.position.z); // Quaternions. message.values.Add(transform.rotation.x); message.values.Add(transform.rotation.y); message.values.Add(transform.rotation.z); message.values.Add(transform.rotation.w); // inputs message.values.Add(ball_controller.speed); message.values.Add(ball_controller.steering); //osc.Send(message); if (recieving_osc) { ReceiveOSC reciever = GetComponent <ReceiveOSC>(); if (reciever.canSendPacket()) { Debug.Log(message); osc.Send(message); reciever.sentPacket(); Debug.Log("send packet"); } else { Debug.Log("cannot send packet!"); } } else { osc.Send(message); } } }
static void Main(string[] args) { var options = ProgramOptions.Parse(args); if (options.Mode == ProgramMode.Experiments) { var runner = new ExperimentRunner(options); runner.Run(); } else { var runner = new InstanceRunner(options); runner.Run(); } }
static void CheckExperimentCreated(ExperimentRunner runner) { if (!EditorPrefs.HasKey(ExperimentKey)) { return; } string typeName = EditorPrefs.GetString(ExperimentKey); EditorPrefs.DeleteKey(ExperimentKey); string pathToTrialScript = "Assets/" + typeName + ".cs"; runner.scriptReferences.DragExperimentScriptHere = AssetDatabase.LoadAssetAtPath(pathToTrialScript, typeof(TextAsset)) as MonoScript; }
static void CheckDesignFile(ExperimentRunner runner) { if (!EditorPrefs.HasKey(DesignFileKey)) { return; } string typeName = EditorPrefs.GetString(DesignFileKey); EditorPrefs.DeleteKey(DesignFileKey); string pathToTrialScript = "Assets/" + typeName + ".asset"; runner.SetExperimentDesignFile(AssetDatabase.LoadAssetAtPath(pathToTrialScript, typeof(ScriptableObject)) as ExperimentDesignFile2); }
static void ScriptReloaded() { AssetDatabase.Refresh(); ExperimentRunner runner = CheckRunnerCreated(); if (runner == null) { return; } CheckTrialCreated(runner); CheckBlockCreated(runner); CheckExperimentCreated(runner); CheckDesignFile(runner); }
//constructor. you don't need to worry about this. public TutorialSampleTrialScript(ExperimentRunner runner, DataRow data) : base(runner, data) { }
public TutorialSampleBlockScript(ExperimentRunner runner, DataTable trialTable, DataRow dataRow, int index) : base(runner, trialTable, dataRow, index) { }
public static void CheckMainWindowIsOpen(ExperimentRunner experimentRunner) { OnCheckMainWindowIsOpen?.Invoke(experimentRunner); }
public NIRS_Trial(ExperimentRunner runner, DataRow data) : base(runner, data) { }
// // You usually want to store a reference to your Experiment runner // YourCustomExperimentRunner myRunner; // Required Constructor. Good place to set up references to objects in the unity scene public ComplexBlockScript(ExperimentRunner runner, DataTable trialTable, DataRow data, int index) : base(runner, trialTable, data, index) { // myRunner = (YourCustomExperimentRunner)runner; //cast the generic runner to your custom type. // GameObject myGameObject = myRunner.MyGameObject; // get reference to gameObject stored in your custom runner }
public BlockSequenceRunner(ExperimentRunner runner, List <Block> blocks) { OnEnable(); this.runner = runner; this.blocks = blocks; }
static void Main(string[] args) { if (!Optimizer.TryUseNativeMKL()) { Console.Error.WriteLine("Could not use MKL native library"); } var command = Command.Help; var nnJsonPath = ""; var isVerbose = false; var outputPath = ""; var imagePath = ""; var print = false; var evaluate = false; var dump = false; var isEncoder = false; var normalize = false; //mlp params int[] layersSizes = { 70, 100, 10 }; var learningRate = 0.3; var momentum = 0.9; double errorThreshold = 0; var batchSize = 10; var activationFunction = ActivationFunction.Sigmoid; var initialWeightsRange = 0.25; var lambda = 0.0; var takeBest = false; var imageWidth = 7; var maxEpochs = 200; string experimentValues = null; var experiment = Experiment.LearningRate; var repetitions = 3; ICommandLine commandLine = CommandLine .Help("h") .Help("help") .Command("test", () => command = Command.Test, true, "Test your MLP") .DefaultParameter("mlp", json => nnJsonPath = json, "MLP data in json format", "Json") .Parameter("image", path => imagePath = path, "Path to image", "Path to image") .Option("v", () => isVerbose = true, "Explain what is happening") .Option("verbose", () => isVerbose = true, "Explain what is happening") .Option("e", () => evaluate = true, "Evaluate using MNIST dataset") .Option("evaluate", () => evaluate = true, "Evaluate using MNIST dataset") .Option("n", () => normalize = true, "Normalize input") .Option("normalize", () => normalize = true, "Normalize input") .Command("train", () => command = Command.Train, "Train new MLP") .DefaultParameter("output", path => outputPath = path, "Output file to save trained mlp") .Parameter("sizes", sizes => layersSizes = JsonConvert.DeserializeObject <int[]>(sizes), "Number of layer and its sizes, default to [70,5,10]", "Sizes") .Parameter("learning-rate", val => learningRate = double.Parse(val, CultureInfo.InvariantCulture), "Learning rate") .Parameter("momentum", val => momentum = double.Parse(val, CultureInfo.InvariantCulture), "Momenum parameter") .Parameter("error-threshold", val => errorThreshold = double.Parse(val, CultureInfo.InvariantCulture), "Error threshold to set learning stop criteria") .Parameter("max-epochs", val => maxEpochs = int.Parse(val), "Program will terminate learning if reaches this epoch") .Parameter("batch-size", val => batchSize = int.Parse(val), "Batch size") .Parameter("activation", val => activationFunction = ParseActivationFunction(val), "Activation function, (sigmoid, tanh)") .Parameter("initial-weights", val => initialWeightsRange = double.Parse(val, CultureInfo.InvariantCulture), "Initial weights range [number](-number;number)") .Parameter("lambda", val => lambda = double.Parse(val, CultureInfo.InvariantCulture), "Lambda param for L2 regularization. Defaults to 0 (no regularization)") .Option("v", () => isVerbose = true, "Explain what is happening") .Option("verbose", () => isVerbose = true, "Explain what is happening") .Option("d", () => dump = true, "Dump training data") .Option("dump", () => dump = true, "Dump training data") .Option("n", () => normalize = true, "Normalize input") .Option("normalize", () => normalize = true, "Normalize input") .Option("e", () => isEncoder = true, "Use encoder mode") .Option("encoder", () => isEncoder = true, "Use encoder mode") .Option("take-best", () => takeBest = true, "Tries to pick best solution from all epochs") .Command("view", () => command = Command.View, "Show MNIST image") .DefaultParameter("path", path => imagePath = path, "Path to image") .Option("p", () => print = true, "Display grayscale interpretation") .Option("print", () => print = true, "Display grayscale interpretation") .Option("n", () => normalize = true, "Normalize input") .Option("normalize", () => normalize = true, "Normalize input") .Command("experiment", () => command = Command.Experiment, "Run experiment") .DefaultParameter("output", path => outputPath = path, "Path to save data") .Parameter("values", val => experimentValues = val, "Values to test in experiment", "Experiment values") .Parameter("experiment", val => experiment = ParseExperimentType(val), "Momenum parameter") .Parameter("sizes", sizes => layersSizes = JsonConvert.DeserializeObject <int[]>(sizes), "Number of layer and its sizes, default to [70,5,10]", "Sizes") .Parameter("learning-rate", val => learningRate = double.Parse(val, CultureInfo.InvariantCulture), "Learning rate") .Parameter("momentum", val => momentum = double.Parse(val, CultureInfo.InvariantCulture), "Momenum parameter") .Parameter("error-threshold", val => errorThreshold = double.Parse(val, CultureInfo.InvariantCulture), "Error threshold to set learning stop criteria") .Parameter("max-epochs", val => maxEpochs = int.Parse(val), "Program will terminate learning if reaches this epoch") .Parameter("batch-size", val => batchSize = int.Parse(val), "Batch size") .Parameter("activation", val => activationFunction = ParseActivationFunction(val), "Activation function, (sigmoid, tanh)") .Parameter("repetitions", val => repetitions = int.Parse(val, CultureInfo.InvariantCulture), "Number of repetitions for each value in experiment") .Parameter("initial-weights", val => initialWeightsRange = double.Parse(val, CultureInfo.InvariantCulture), "Initial weights range [number](-number;number)") .Parameter("lambda", val => lambda = double.Parse(val, CultureInfo.InvariantCulture), "Lambda param for L2 regularization. Defaults to 0 (no regularization)") .Option("v", () => isVerbose = true, "Explain what is happening") .Option("verbose", () => isVerbose = true, "Explain what is happening") .Option("n", () => normalize = true, "Normalize input") .Option("normalize", () => normalize = true, "Normalize input") .Option("e", () => isEncoder = true, "Use encoder mode") .Option("encoder", () => isEncoder = true, "Use encoder mode") .Command("features", () => command = Command.Features, "Print features") .Parameter("mlp", json => nnJsonPath = json, "MLP data in json format", "Json") .Parameter("output", path => outputPath = path, "Path to save features") .Parameter("width", val => imageWidth = int.Parse(val), "Input width to display feature as image") .Command("encoder", () => command = Command.Encoder, "Use encoder mode") .Parameter("mlp", json => nnJsonPath = json, "Encoder data in json format", "Json") .Parameter("image", path => imagePath = path, "Path to image", "Path to image") .Option("n", () => normalize = true, "Normalize input") .Option("normalize", () => normalize = true, "Normalize input") .End(); commandLine.Run(args); switch (command) { case Command.Train: { try { File.Create(outputPath).Close(); } catch (Exception) { Console.WriteLine($"Path is invalid"); return; } //Debugger.Launch(); var options = new NeuralNetworkOptions( learningRate, momentum, errorThreshold, layersSizes, isEncoder ? ENCODER_DATA_PATH : TRAINING_DATA_PATH, VALIDATION_PATH, TEST_DATA_PATH, maxEpochs, isVerbose, batchSize, activationFunction, initialWeightsRange, dump, normalize, isEncoder, lambda, takeBest ); var trainingResult = MnistTrainer.TrainOnMnist(options); var mlp = trainingResult.NeuralNetwork; File.WriteAllText(outputPath, mlp.ToJson()); if (dump) { var fi = new FileInfo(outputPath); var directory = fi.Directory?.FullName ?? ""; var fileName = Path.GetFileNameWithoutExtension(outputPath); directory += $"/{fileName}_"; ExperimentVisualization.GenerateErrorPlot(trainingResult, $"{directory}error", $"{fileName} - error"); if (!isEncoder) { ExperimentVisualization.GenerateEvaluationPlot(trainingResult, $"{directory}evaluation", $"{fileName} - evaluation"); } } break; } case Command.Test: { NeuralNetwork mlp; try { var json = File.ReadAllText(nnJsonPath); mlp = JsonConvert.DeserializeObject <NeuralNetwork>(json); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine($"Path is invalid"); return; } if (!string.IsNullOrEmpty(imagePath)) { if (!File.Exists(imagePath)) { Console.WriteLine($"File {imagePath} does not exist!"); return; } var image = MnistParser.ReadImage(imagePath, normalize, isEncoder); var decision = mlp.Compute(image.Values); Console.WriteLine($"Result - {decision}"); Console.WriteLine($"Expected - {image.Label}"); } if (evaluate) { var testData = MnistParser.ReadAll(TEST_DATA_PATH, normalize, isEncoder); var evaluation = mlp.Evaluate(testData); Console.WriteLine($"Solutions - {evaluation.Correct} / {evaluation.All}"); Console.WriteLine($"Fitness - {evaluation.Percentage}"); } break; } case Command.View: { if (string.IsNullOrEmpty(imagePath)) { Console.WriteLine($"Path to image not set"); return; } if (!File.Exists(imagePath)) { Console.WriteLine($"File {imagePath} does not exist!"); return; } var model = MnistParser.ReadImage(imagePath, normalize, isEncoder); var modelDump = MnistViewer.Dump(model); Console.WriteLine(modelDump); if (print) { var modelMatrix = MnistViewer.ToMatrix(model.Values, model.Width); Console.Write(modelMatrix); } break; } case Command.Help: commandLine.Run("help"); break; case Command.Experiment: { var options = new NeuralNetworkOptions( learningRate, momentum, errorThreshold, layersSizes, isEncoder ? ENCODER_DATA_PATH : TRAINING_DATA_PATH, VALIDATION_PATH, TEST_DATA_PATH, maxEpochs, isVerbose, batchSize, activationFunction, initialWeightsRange, true, normalize, isEncoder, lambda, takeBest ); switch (experiment) { case Experiment.LearningRate: { var values = JsonConvert.DeserializeObject <double[]>(experimentValues); ExperimentRunner.RunLearningRateExperiment( values, options, repetitions, outputPath ); break; } case Experiment.ActivationFunction: { var values = JsonConvert.DeserializeObject <ActivationFunction[]>(experimentValues); ExperimentRunner.RunActivationFunctionExperiment( values, options, repetitions, outputPath ); break; } case Experiment.Momentum: { var values = JsonConvert.DeserializeObject <double[]>(experimentValues); ExperimentRunner.RunMomentumExperiment( values, options, repetitions, outputPath ); break; } case Experiment.InitialWeights: { var values = JsonConvert.DeserializeObject <double[]>(experimentValues); ExperimentRunner.RunInitialWeightsRangeExperiment( values, options, repetitions, outputPath ); break; } case Experiment.Sizes: { var values = JsonConvert.DeserializeObject <int[][]>(experimentValues); ExperimentRunner.RunSizeExperiment( values, options, repetitions, outputPath ); break; } default: throw new ArgumentOutOfRangeException(); } break; } case Command.Features: { NeuralNetwork mlp; try { var json = File.ReadAllText(nnJsonPath); mlp = JsonConvert.DeserializeObject <NeuralNetwork>(json); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine($"Path is invalid"); return; } var layerFeatures = mlp.GetFeatures(); if (Directory.Exists(outputPath)) { Directory.Delete(outputPath, true); } Directory.CreateDirectory(outputPath); for (int layerIndex = 0; layerIndex < layerFeatures.Length; layerIndex++) { var features = layerFeatures[layerIndex]; var path = $"{outputPath}/{layerIndex}"; Directory.CreateDirectory(path); for (int i = 0; i < features.Length; i++) { var feature = features[i]; var image = MnistViewer.ToImage(feature, imageWidth); image.Save($"{path}/{i}.png", ImageFormat.Png); } } break; } case Command.Encoder: { Encoder.Network.Encoder encoder; try { var json = File.ReadAllText(nnJsonPath); encoder = JsonConvert.DeserializeObject <Encoder.Network.Encoder>(json); } catch (Exception e) { Console.WriteLine(e); Console.WriteLine($"Path is invalid"); return; } if (!string.IsNullOrEmpty(imagePath)) { if (!File.Exists(imagePath)) { Console.WriteLine($"File {imagePath} does not exist!"); return; } var image = MnistParser.ReadImage(imagePath, normalize, true); var recreatedData = encoder.Compute(image.Values); var recreatedImage = MnistViewer.ToImage(recreatedData, imageWidth); File.Copy(imagePath, "original.png", true); recreatedImage.Save($"decoded.png", ImageFormat.Png); } break; } default: throw new ArgumentOutOfRangeException(); } }
// // You usually want to store a reference to your experiment runner // YourCustomExperimentRunner myRunner; // Required Constructor. Good place to set up references to objects in the unity scene public TutorialSampleExperimentScript(ExperimentRunner runner, RunnableDesign runnableDesign) : base(runner, runnableDesign) { // myRunner = (YourCustomExperimentRunner)runner; //cast the generic runner to your custom type. // GameObject myGameObject = myRunner.MyGameObject; // get reference to gameObject stored in your custom runner }
public static void InitExperiment(ExperimentRunner experimentRunner) { OnInitExperiment?.Invoke(experimentRunner); }
/// <summary> /// Constructor just calls the base class Trail's constructor. /// </summary> /// <param name="runner">The Runner being run</param> /// <param name="data">The row of BlockData for this trial from a table</param> public SimpleTrial(ExperimentRunner runner, DataRow data) : base(runner, data) { }
public SimpleExperiment(ExperimentRunner runner, ExperimentDesign design) : base(runner, design) { }
// // You usually want to store a reference to your experiment runner // YourCustomExperimentRunner myRunner; // Required Constructor. Good place to set up references to objects in the unity scene public ___ExperimentClassName___(ExperimentRunner runner, RunnableDesign runnableDesign) : base(runner, runnableDesign) { // myRunner = (YourCustomExperimentRunner)runner; //cast the generic runner to your custom type. // GameObject myGameObject = myRunner.MyGameObject; // get reference to gameObject stored in your custom runner }
public ExperimentDesign ToTable(ExperimentRunner experimentRunner, bool shuffleTrialOrder, int numberRepetitions, bool shuffleTrialsBetweenBlocks) { //Debug.Log($"ToTable method in IndependentVariable: Alldata.count {AllVariables.Count}"); return(new ExperimentDesign(experimentRunner, AllVariables, shuffleTrialOrder, numberRepetitions, shuffleTrialsBetweenBlocks)); }
public TrialSequenceRunner(ExperimentRunner runner, List <Trial> trialList) { OnEnable(); trialsInSequence = trialList; currentTrialList = trialList; }