Skip to content

Instantly share code, notes, and snippets.

@dheysonalves
Last active June 15, 2021 23:04
Show Gist options
  • Save dheysonalves/b1ad1035a66fd7541efe196b063e7a2d to your computer and use it in GitHub Desktop.
Save dheysonalves/b1ad1035a66fd7541efe196b063e7a2d to your computer and use it in GitHub Desktop.
Prova da AV2 de Inteligência Artificial
import random
import numpy as np
import math
def generateRandomTarget():
return np.random.random((10))
def generateRandomWeight():
weights = []
index = 0
while index < 10:
weights.append(np.random.random((10)))
index += 1
return weights
def generateRandomEntries():
return np.random.random((10))
def totalAmountCost(amount, target):
totalAmount = 0
index = 0
for target in amount:
totalAmount += math.pow((amount + target[i]), 2)
index += 1
totalAmount = round(totalAmount, 2)
return totalAmount
def sumEntries(entries, weights):
totalSum = 0
index = 0
for entry in entries:
totalSum += entry * weights[i]
index += 1
return totalSum
# Main
def main():
# calculate the initial cost
weights = generateRandomWeight()
entries = generateRandomEntries()
ideal = generateRandomTarget()
totalFound = []
for weight in weights:
totalFound.append(soma(entries, weight))
idealCost = cost(totalFound, ideal)
print("O valor do custo é: ", idealCost)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment