/// <summary>
 /// Function called each frame
 /// </summary>
 void Update()
 {
     if (save)
     {
         save = false; dS.saveOnFile();
     }
 }
예제 #2
0
    /// <summary>
    /// Save on file a parameters+changes configuration
    /// </summary>
    /// <param name="stats">array of parameters</param>
    /// <param name="pc">array of potencial changes</param>
    void SaveStats(float[] stats, float[] pc)
    {
        string[] attributes = new string[myVals.Length];
        for (int i = 0; i < myVals.Length; i++)
        {
            attributes[i] = "Attr" + (i + 1).ToString();
        }

        dataSaver ds = new dataSaver(folder + "\\Stat" + indxSaving + ".fit #" + bestFitness + "#", attributes);

        ds.addLine(stats);
        ds.addLine(pc);
        ds.saveOnFile();
        indxSaving++;
    }
예제 #3
0
    /// <summary>
    /// Save a set of parameters to a file.
    /// <para>This function is used to save the parameters of the best individuals</para>
    /// </summary>
    /// <param name="keys">array of parameters used for an experiment</param>
    /// <param name="fitness">fitness obtained with that set of keys</param>
    void SaveStats(float[] keys, float fitness)
    {
        if (!autoSave)
        {
            return;
        }

        float[] stats = new float[keys.Length + 1];
        stats[0] = fitness;
        for (int i = 1; i < stats.Length; i++)
        {
            stats[i] = keys[i - 1];
        }

        dataSaver ds = new dataSaver(folder + "\\Stat" + indxSaving + ".gen " + actGeneration + ".fit #" + fitness + "#", attributes);

        ds.addLine(stats);
        ds.saveOnFile();
        indxSaving++;
    }
예제 #4
0
    /// <summary>
    /// Function called each frame
    /// </summary>
    void Update()
    {
        if (save)
        {
            save = false; ds.saveOnFile();
        }

        // if the boolean 'readFile' is true, we substitute the array setted in the editor with the one in the file
        // in this way is possible to continue the training until a certain point and later start from that point
        if (readFile)
        {
            float[,] t = dataReader.readFile(folder + "\\" + PathFileToRead);
            if (t == null)
            {
                Debug.Log("Check the filename"); readFile = false; return;
            }

            for (int i = 0; i <= t.GetUpperBound(1); i++)
            {
                myVals[i] = t[0, i];
            }
            for (int i = 0; i <= t.GetUpperBound(1); i++)
            {
                potencialChanges[i] = t[1, i];
            }

            Debug.Log("file readed");
            readFile    = false;
            twiddleStep = -2;
            iPC         = 0;
        }
        else if (twiddle())
        {
            Debug.Log("Experiment finished");
        }
    }