Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class Functions : MonoBehaviour
- {
- public float theta;
- // Start is called before the first frame update
- void Start()
- {
- //Debug.Log("Sign " + Sign(15));
- //Debug.Log("Sign " + Sign(-15));
- //Debug.Log("Step " + Step(15));
- //Debug.Log("Step " + Step(-15));
- //Debug.Log("Sigmoid " + Sigmoid(15));
- //Debug.Log("Sigmoid " + Sigmoid(-15));
- //Quad(4.123456789f, 4.123456789f);
- float[] x = new float[3] { 0.1f, 0.5f, 0.8f };
- float[] w = new float[3] { 0.7f, 0.2f, 0.6f };
- Debug.Log("Step " + Step(Activate(x, w), 0.5f));
- x = new float[3] { 0.1f, 0.5f, 0.8f };
- w = new float[3] { 0.7f, 0.2f, 0.6f };
- Debug.Log("Sign " + Sign(Activate(x, w), 0.7f));
- x = new float[3] { 0.1f, 0.5f, 0.8f };
- w = new float[3] { 0.7f, 0.2f, 0.6f };
- Debug.Log("Sigmoid " + Sigmoid(Activate(x, w), -0.7f));
- x = new float[3] { 0.1f, 0.5f, 0.8f };
- w = new float[3] { 0.7f, 0.2f, 0.6f };
- Debug.Log("Liniear " + Liniear(Activate(x, w), 0.7f));
- x = new float[3] { 0.9f, 0.6f, 0.3f };
- w = new float[3] { -0.4f, 0.7f, -0.1f };
- Debug.Log("2nd Step " + Step(Activate(x, w), 0.2f));
- x = new float[3] { 0.9f, 0.6f, 0.3f };
- w = new float[3] { -0.4f, 0.7f, -0.1f };
- Debug.Log("2nd Sign " + Sign(Activate(x, w), 0.0f));
- x = new float[3] { 0.9f, 0.6f, 0.3f };
- w = new float[3] { -0.4f, 0.7f, -0.1f };
- Debug.Log("2nd Sigmoid " + Sigmoid(Activate(x, w), -0.0f));
- x = new float[3] { 0.9f, 0.6f, 0.3f };
- w = new float[3] { -0.4f, 0.7f, -0.1f };
- Debug.Log("2nd Liniear " + Liniear(Activate(x, w), 0.0f));
- }
- public float Activate(float[] x, float[] w)
- {
- float output = 0.0f;
- int n = x.Length;
- for (int i = 0; i < n; i++)
- {
- output += x[i] * w[i];
- }
- //Debug.Log("Activate " + output);
- return output;
- }
- public float Sign(float _x, float _theta)
- {
- if (_x >= _theta)
- {
- return 1.0f;
- }
- else
- {
- return -1.0f;
- }
- }
- public float Step(float _x, float _theta)
- {
- if (_x >= _theta)
- {
- return 1.0f;
- }
- else
- {
- return 0.0f;
- }
- }
- public float Liniear(float _x, float _theta)
- {
- return _x - _theta;
- }
- public float Sigmoid(float _x, float _theta)
- {
- return 1.0f / (1.0f + Mathf.Pow((float)Math.E, -(_x - _theta)));
- }
- public void Quad(float _g, float _f)
- {
- float a, b, c, x1, x2;
- int i = 0;
- bool check = true;
- while(check)
- {
- string ftext = _f.ToString();
- if (ftext.Contains(".") && ftext.IndexOf(".") >= ftext.Length - i) //delete the > sine if you want only 2 decimal places but don't delete it if you want also 1 decimal places.
- {
- Debug.Log("Has places: " + i);
- check = false;
- }
- if (i > 100) check = false;
- i++;
- }
- int f, g;
- g = 123456750;
- f = 123456747;
- a = g - f;
- b = 2.0f;
- c = 1.0f;
- a /= 10;
- Debug.Log(a);
- x1 = (-b - Mathf.Sqrt(b * b - 4 * a * c)) / (2 * a);
- x2 = (-b + Mathf.Sqrt(b * b - 4 * a * c)) / (2 * a);
- Debug.Log(x1);
- Debug.Log(x2);
- Debug.Log(((a * (x1 * x1)) + (b * x1) + c));
- Debug.Log(((a * (x2 * x2)) + (b * x2) + c));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement