machinelearning

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c84f4c84ad727ab3593f8f33614bd664f162b10e
parent cfc8c125e9850e1f70183273adb744aae1344f01
Author: Andrew <andrewlaack1@gmail.com>
Date:   Thu, 18 Apr 2024 17:48:02 -0500

rename file

Diffstat:
DGradientDescentThirdDegreePolynomial.py | 47-----------------------------------------------
AGradientDescentThirdDegreePolynomialV1.py | 46++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 47 deletions(-)

diff --git a/GradientDescentThirdDegreePolynomial.py b/GradientDescentThirdDegreePolynomial.py @@ -1,47 +0,0 @@ -import random -print("ax^3 + bx^2 + cx + d") - -a = float(input("Enter a: ")) -b = float(input("Enter b: ")) -c = float(input("Enter c: ")) -d = float(input("Enter d: ")) - - -def calculateValue(x): - return x**3 * a + x**2 * b + x * c + d - - -def printResult(x, y): - print("x: " + str(x) + " y: " + str(y)) - - -# Find the x at the bottom -def descend(x, depth): - - if depth > 100: - return x - - midX = x - rightX = x + .00000001 - leftX = x - .00000001 - - midY = calculateValue(midX) - rightY = calculateValue(rightX) - leftY = calculateValue(leftX) - - printResult(leftX, leftY) - printResult(midX, midY) - printResult(rightX, rightY) - - depth += 1 - if rightY > leftY: - return descend(x - (1 / depth), depth) - else: - return descend(x + (1/depth), depth) - - -currSearch = random.random() * 10 -xVal = descend(currSearch, 0) - -printResult(xVal, calculateValue(xVal)) - diff --git a/GradientDescentThirdDegreePolynomialV1.py b/GradientDescentThirdDegreePolynomialV1.py @@ -0,0 +1,46 @@ +import random +print("ax^3 + bx^2 + cx + d") + +a = float(input("Enter a: ")) +b = float(input("Enter b: ")) +c = float(input("Enter c: ")) +d = float(input("Enter d: ")) + + +def calculateValue(x): + return x**3 * a + x**2 * b + x * c + d + + +def printResult(x, y): + print("x: " + str(x) + " y: " + str(y)) + + +# Find the x at the bottom +def descend(x, depth): + + if depth > 100: + return x + + midX = x + rightX = x + .00000001 + leftX = x - .00000001 + + midY = calculateValue(midX) + rightY = calculateValue(rightX) + leftY = calculateValue(leftX) + + printResult(leftX, leftY) + printResult(midX, midY) + printResult(rightX, rightY) + + depth += 1 + if rightY > leftY: + return descend(x - (1 / depth), depth) + else: + return descend(x + (1/depth), depth) + + +currSearch = random.random() * 10 +xVal = descend(currSearch, 0) + +printResult(xVal, calculateValue(xVal))