Skip to content

Instantly share code, notes, and snippets.

View scandoleiro's full-sized avatar

Liliane Vieira scandoleiro

View GitHub Profile
@scandoleiro
scandoleiro / gist:58ed2417af8276f7241a52b7d9d7803a
Last active May 7, 2020 18:06
Calcula da hessiana e atualização - Broyden-Fletcher-Goldfarb-Shanno (BFGS)
import numpy as np
import scipy.linalg as la
import numpy.linalg as ln
#Busca valor de alpha
def LineSearch(f,g,x,p):
a,b = 1 - 2/(1 + np.sqrt(5)), 2/(1+np.sqrt(5))
alpha = 1.0
while (f(x+alpha*p) > f(x)) + a * alpha*np.dot(g(x),p) :
alpha *= b
# Function to generate a truth table (number of variables of the table (fixed number), number of variables of the table (recursive))
def geraTabelaVerdade(m,n,tabelaVerdade):
bits=2**m # rows in the table, fixed value
repeticoes_coluna=(bits//(2**n))*2
repeticoes_linha=(2**n//2)//2
contador=0
if not tabelaVerdade: # Create the first column
for i in range(bits // 2):
tabelaVerdade.append('0')
for i in range(bits // 2):