コード例 #1
0
def test_initial_guess3():
    x0 = [-1, 1]

    def f(args):
        [x, y] = args
        ans = 100 * (y - x**2)**2 + (1 - x)**2
        return ans

    demo = SteepestDescent(f, x0)
    root_est = demo.find_root()
    real_root = np.array([1., 1.])
    assert real_root.all() == root_est.all()
コード例 #2
0
ファイル: vns.py プロジェクト: marcoazza/eternityII
    def __init__(self):
        self.current = Board()
        self.best = Board()
        random.seed()
        self.k = 1
        self.k_max = None
        self.max_score = None
        self.N = 0
        self.local_search = SteepestDescent()

        self.chances = {
            Tile.CENTRAL: 0.0,
            Tile.BORDER: 0.0,
            Tile.CORNER: 0.0,
        }

        self.prob_map = {
            Tile.CENTRAL: 0.0,
            Tile.BORDER: 0.0,
            Tile.CORNER: 0.0,
        }
        self.total = 25.0
コード例 #3
0
from modeller import *
from modeller.optimizers import actions
from modeller.scripts import complete_pdb

# Load our custom steepest descent optimizer
from steepest_descent import SteepestDescent

env = environ()
env.io.atom_files_directory = ['../atom_files']
env.libs.topology.read(file='$(LIB)/top_heav.lib')
env.libs.parameters.read(file='$(LIB)/par.lib')

# Read in the initial structure:
code = '1fdn'
mdl = complete_pdb(env, code)
atmsel = selection(mdl)

# Generate the restraints:
mdl.restraints.make(atmsel, restraint_type='stereo', spline_on_site=False)

# Optimize with our custom optimizer:
opt = SteepestDescent(max_iterations=80)
opt.optimize(atmsel, actions=actions.trace(5))
コード例 #4
0
import AnnoDomini.AutoDiff as AD
import numpy as np
from matplotlib import pyplot as plt
from scipy import linalg as la
from steepest_descent import SteepestDescent
from matplotlib import pyplot as plt


def f(args):
    [x, y] = args
    ans = 100 * (y - x**2)**2 + (1 - x)**2
    return ans


x0 = [2, 1]
sd = SteepestDescent(f, x0)
root = sd.find_root()
traj = sd.xs

x = [traj[i][0] for i in range(len(traj))]
y = [traj[i][1] for i in range(len(traj))]
traj2 = np.concatenate(
    (np.array(x).reshape(-1, 1), np.array(y).reshape(-1, 1)), axis=1)
# print(root)
# print(traj2)


def plot_descent(ans):
    X, Y = np.meshgrid(np.linspace(-3, 3, 100), np.linspace(-2, 8, 100))
    Z = f(np.array([X, Y]))
    fig = plt.subplots(1, 1, figsize=(10, 7))