Exemplo n.º 1
0
    public GameObject Generate()
    {
        // Create objects grouped by "Generated Objects" GameObject.
        GameObject parent_object = new GameObject("Generated Objects");

        // Create the object under same parent as this script.
        parent_object.transform.parent = gameObject.transform.parent;


        // Create the objects with randomized position and scale.
        for (int i = 0; i <= count; ++i)
        {
            GameObject instantiated_obj = Instantiate(object_to_instantiate) as GameObject;

            //instantiated_obj.transform.position = new Vector3(Random.Range(-pos_range, pos_range),
            //                                                  Random.Range(-pos_range, pos_range),
            //                                                  Random.Range(-pos_range, pos_range));

            instantiated_obj.transform.position = new Vector3(RandomFromDistribution.RandomRangeNormalDistribution(-pos_range, pos_range, RandomFromDistribution.ConfidenceLevel_e._999),
                                                              0,
                                                              RandomFromDistribution.RandomRangeNormalDistribution(-pos_range, pos_range, RandomFromDistribution.ConfidenceLevel_e._999));

            float scale;
            switch (size_range_type)
            {
            case SizeRangeType_e.Uniform:
                scale = Random.Range(min_size, max_size);
                break;

            case SizeRangeType_e.LinearRight:
                scale = RandomFromDistribution.RandomRangeLinear(min_size, max_size, 1.0f);
                break;

            case SizeRangeType_e.LinearLeft:
                scale = RandomFromDistribution.RandomRangeLinear(min_size, max_size, -1.0f);
                break;

            case SizeRangeType_e.Normal:
                scale = RandomFromDistribution.RandomRangeNormalDistribution(min_size, max_size, RandomFromDistribution.ConfidenceLevel_e._999);
                break;

            case SizeRangeType_e.CurveRight:
                scale = RandomFromDistribution.RandomRangeSlope(min_size, max_size, 10.0f, RandomFromDistribution.Direction_e.Right);
                break;

            case SizeRangeType_e.CurveLeft:
                scale = RandomFromDistribution.RandomRangeSlope(min_size, max_size, 10.0f, RandomFromDistribution.Direction_e.Left);
                break;

            default:
                scale = Random.Range(min_size, max_size);
                break;
            }
            instantiated_obj.transform.localScale = new Vector3(scale, scale, scale);

            instantiated_obj.transform.parent = parent_object.transform;
        }

        return(parent_object);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (player.transform.position.z < 0 & numTraversalsLocal != sp.numTraversals)
        {
            numTraversalsLocal++;

            if (numTraversalsLocal >= (numBaselineTrials + numTrainingTrials))
            {
                if (nextMorphTrial < 0)
                {
                    nextMorphTrial = numTraversalsLocal + (int)UnityEngine.Mathf.Round(RandomFromDistribution.RandomRangeLinear(-.5f, 3f, 0f));
                    Debug.Log("next morph" + nextMorphTrial.ToString());
                }
                if (numTraversalsLocal == nextMorphTrial)
                {
                    nextMorphTrial = -1;
                    sp.morph       = morphTrials[morphCounter];
                    morphCounter++;
                }
                else
                {
                    sp.morph = NextTrial();
                    trialHistory.Add(sp.morph);
                }
            }
            else if (numTraversalsLocal >= numBaselineTrials)
            {
                sp.morph = NextTrial();
                trialHistory.Add(sp.morph);
            }
            else
            {
                sp.morph = baselineTrials[numTraversalsLocal];
            }
            if (trialHistory.Count > 40)
            {
                trialHistory.RemoveAt(0);
            }
        }
    }
Exemplo n.º 3
0
 protected override float GetRandomNumber(float min, float max)
 {
     return(RandomFromDistribution.RandomRangeLinear(min, max, slope));
 }
Exemplo n.º 4
0
    float NextTrial()
    {
        float e0 = 0f; float e1 = 0f; int i = 0;

        while (pc.LickHistory.Count > 40)
        {
            pc.LickHistory.RemoveAt(0);
        }

        //int i;
        Debug.Log(i);
        Debug.Log(pc.LickHistory.Count);
        if (pc.LickHistory.Count < 40)
        {
            for (int j = 0; j < 40 - pc.LickHistory.Count; j++)
            {
                e1 = e1 + .5f * Pr_vec[j];
                e0 = e0 + .5f * Pr_vec[j];
            }
            i = 40 - pc.LickHistory.Count;
        }
        else
        {
            i = 0;
        }

        foreach (float j in pc.LickHistory)
        {
            //Debug.Log(i);
            if (j == -1)
            {
                Debug.Log(i);
                e1 = e1 + Pr_vec[i];
            }
            else if (j == 1)
            {
                Debug.Log(i);
                e0 = e0 + Pr_vec[i];
            }

            i++;
        }


        float p1;

        if (e0 + e1 == 0f)
        {
            p1 = .5f;
        }
        else
        {
            p1 = Mathf.Sqrt(e1) / (Mathf.Sqrt(e1) + Mathf.Sqrt(e0));
        }

        if (p1 > .85f)
        {
            p1 = .85f;
        }
        else if (p1 < .15f)
        {
            p1 = .15f;
        }
        ;
        Debug.Log(p1);
        float sum = 0; int k = 0;

        foreach (float j in trialHistory)
        {
            sum = sum + j * P_corrector_vec[k];
            k++;
        }
        float emp_p1 = sum / (float)trialHistory.Count;

        float thresh;

        if (p1 > emp_p1)
        {
            thresh = .5f * p1;
        }
        else
        {
            thresh = .5f * (1 + p1);
        }


        if (RandomFromDistribution.RandomRangeLinear(0f, 1f, 0f) < p1)
        {
            return(1f);
        }
        else
        {
            return(0f);
        }
    }