Ejemplo n.º 1
0
    public void UseGAN(int generatedNumber)
    {
        var balls = gameSystem.GetBallsStatus();

        float[,] conditionsAll = new float[generatedNumber, balls.Count * 3];

        for (int iball = 0; iball < balls.Count; ++iball)
        {
            for (int i = 0; i < generatedNumber; ++i)
            {
                conditionsAll[i, iball *3]      = balls[iball].x;
                conditionsAll[i, iball * 3 + 1] = balls[iball].y;
                conditionsAll[i, iball * 3 + 2] = balls[iball].z;
            }
        }

        float[,] generated = (float[, ])modelRef.GenerateBatch(conditionsAll, MathUtils.GenerateWhiteNoise(generatedNumber, -1, 1, modelRef.inputNoiseShape));

        dataPlane.RemovePointsOfType(1);
        dataPlane.RemovePointsOfType(0);
        for (int i = 0; i < generatedNumber; ++i)
        {
            dataPlane.AddDatapoint(new Vector2(generated[i, 0] / 2, generated[i, 1]) / 2, 1);
        }

        dataPlane.AddDatapoint(new Vector2(0.5f, 0.5f), 0);
        dataPlane.AddDatapoint(new Vector2(-0.5f, -0.5f), 0);
        dataPlane.AddDatapoint(new Vector2(0.5f, -0.5f), 0);
        dataPlane.AddDatapoint(new Vector2(-0.5f, 0.5f), 0);
        dataPlane.AddDatapoint(new Vector2(0, 0), 0);
    }
Ejemplo n.º 2
0
    public void UseGAN(int generatedNumber)
    {
        float[,] generated = (float[, ])modelRef.GenerateBatch(null, MathUtils.GenerateWhiteNoise(generatedNumber, -1f, 1f, modelRef.inputNoiseShape));

        dataPlane.RemovePointsOfType(1);
        for (int i = 0; i < generatedNumber; ++i)
        {
            dataPlane.AddDatapoint(new Vector2(generated[i, 0], generated[i, 1]), 1);
        }
    }
Ejemplo n.º 3
0
    public float TrainDiscriminatorBatch(int batchSize)
    {
        //fetch data from data buffer
        var fetchesForFake = new List <ValueTuple <string, int, string> >();
        var fetchesForReal = new List <ValueTuple <string, int, string> >();

        fetchesForReal.Add(new ValueTuple <string, int, string>("Target", 0, "Target"));
        if (ganReference.HasConditionInput)
        {
            fetchesForFake.Add(new ValueTuple <string, int, string>("Condition", 0, "Condition"));
            fetchesForReal.Add(new ValueTuple <string, int, string>("Condition", 0, "Condition"));
        }
        var samplesForFake = dataBuffer.RandomSample(batchSize, fetchesForFake.ToArray());
        var samplesForReal = dataBuffer.RandomSample(batchSize, fetchesForReal.ToArray());

        Array conditionsForFake = samplesForFake.ContainsKey("Condition") ? samplesForFake["Condition"] : null;
        Array conditionsForReal = samplesForReal.ContainsKey("Condition") ? samplesForReal["Condition"] : null;
        Array targetsForReal    = samplesForReal["Target"];

        //generate noise
        Array noise = null;

        if (ganReference.HasNoiseInput)
        {
            noise = MathUtils.GenerateWhiteNoise(batchSize, -1, 1, ganReference.inputNoiseShape);
        }
        //genrate fake data
        Array generatedFake = ganReference.GenerateBatch(conditionsForFake, noise);

        //genreate labels
        float[,] fakeLabels = new float[batchSize, 1];
        float[,] realLabels = new float[batchSize, 1];
        for (int i = 0; i < batchSize; ++i)
        {
            fakeLabels[i, 0] = 0;
            realLabels[i, 0] = 1;
        }

        //train with fake labels
        float l1 = ganReference.TrainDiscriminatorBatch(generatedFake, fakeLabels, conditionsForFake);
        float l2 = ganReference.TrainDiscriminatorBatch(targetsForReal, realLabels, conditionsForReal);

        return((l1 + l2) / 2);
    }