Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class Functions : MonoBehaviour
  7. {
  8. public float theta;
  9.  
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. //Debug.Log("Sign " + Sign(15));
  14. //Debug.Log("Sign " + Sign(-15));
  15. //Debug.Log("Step " + Step(15));
  16. //Debug.Log("Step " + Step(-15));
  17. //Debug.Log("Sigmoid " + Sigmoid(15));
  18. //Debug.Log("Sigmoid " + Sigmoid(-15));
  19. //Quad(4.123456789f, 4.123456789f);
  20. float[] x = new float[3] { 0.1f, 0.5f, 0.8f };
  21. float[] w = new float[3] { 0.7f, 0.2f, 0.6f };
  22. Debug.Log("Step " + Step(Activate(x, w), 0.5f));
  23.  
  24. x = new float[3] { 0.1f, 0.5f, 0.8f };
  25. w = new float[3] { 0.7f, 0.2f, 0.6f };
  26. Debug.Log("Sign " + Sign(Activate(x, w), 0.7f));
  27.  
  28. x = new float[3] { 0.1f, 0.5f, 0.8f };
  29. w = new float[3] { 0.7f, 0.2f, 0.6f };
  30. Debug.Log("Sigmoid " + Sigmoid(Activate(x, w), -0.7f));
  31.  
  32. x = new float[3] { 0.1f, 0.5f, 0.8f };
  33. w = new float[3] { 0.7f, 0.2f, 0.6f };
  34. Debug.Log("Liniear " + Liniear(Activate(x, w), 0.7f));
  35.  
  36. x = new float[3] { 0.9f, 0.6f, 0.3f };
  37. w = new float[3] { -0.4f, 0.7f, -0.1f };
  38. Debug.Log("2nd Step " + Step(Activate(x, w), 0.2f));
  39.  
  40. x = new float[3] { 0.9f, 0.6f, 0.3f };
  41. w = new float[3] { -0.4f, 0.7f, -0.1f };
  42. Debug.Log("2nd Sign " + Sign(Activate(x, w), 0.0f));
  43.  
  44. x = new float[3] { 0.9f, 0.6f, 0.3f };
  45. w = new float[3] { -0.4f, 0.7f, -0.1f };
  46. Debug.Log("2nd Sigmoid " + Sigmoid(Activate(x, w), -0.0f));
  47.  
  48. x = new float[3] { 0.9f, 0.6f, 0.3f };
  49. w = new float[3] { -0.4f, 0.7f, -0.1f };
  50. Debug.Log("2nd Liniear " + Liniear(Activate(x, w), 0.0f));
  51. }
  52.  
  53. public float Activate(float[] x, float[] w)
  54. {
  55. float output = 0.0f;
  56. int n = x.Length;
  57. for (int i = 0; i < n; i++)
  58. {
  59. output += x[i] * w[i];
  60. }
  61.  
  62. //Debug.Log("Activate " + output);
  63.  
  64. return output;
  65. }
  66.  
  67. public float Sign(float _x, float _theta)
  68. {
  69. if (_x >= _theta)
  70. {
  71. return 1.0f;
  72. }
  73. else
  74. {
  75. return -1.0f;
  76. }
  77. }
  78.  
  79. public float Step(float _x, float _theta)
  80. {
  81. if (_x >= _theta)
  82. {
  83. return 1.0f;
  84. }
  85. else
  86. {
  87. return 0.0f;
  88. }
  89. }
  90.  
  91. public float Liniear(float _x, float _theta)
  92. {
  93. return _x - _theta;
  94. }
  95.  
  96. public float Sigmoid(float _x, float _theta)
  97. {
  98. return 1.0f / (1.0f + Mathf.Pow((float)Math.E, -(_x - _theta)));
  99. }
  100.  
  101. public void Quad(float _g, float _f)
  102. {
  103. float a, b, c, x1, x2;
  104.  
  105. int i = 0;
  106. bool check = true;
  107. while(check)
  108. {
  109. string ftext = _f.ToString();
  110. 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.
  111. {
  112. Debug.Log("Has places: " + i);
  113. check = false;
  114. }
  115.  
  116. if (i > 100) check = false;
  117.  
  118. i++;
  119. }
  120.  
  121. int f, g;
  122.  
  123. g = 123456750;
  124. f = 123456747;
  125. a = g - f;
  126. b = 2.0f;
  127. c = 1.0f;
  128.  
  129. a /= 10;
  130.  
  131. Debug.Log(a);
  132.  
  133. x1 = (-b - Mathf.Sqrt(b * b - 4 * a * c)) / (2 * a);
  134. x2 = (-b + Mathf.Sqrt(b * b - 4 * a * c)) / (2 * a);
  135.  
  136. Debug.Log(x1);
  137. Debug.Log(x2);
  138.  
  139. Debug.Log(((a * (x1 * x1)) + (b * x1) + c));
  140. Debug.Log(((a * (x2 * x2)) + (b * x2) + c));
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement