-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimal.py
24 lines (22 loc) · 857 Bytes
/
optimal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
from trimesh import *
from swf import *
from utils import *
from scipy.optimize import minimize
class OptimalSWF():
def __init__(self, vertices, faces, n=3, level_to_optimize=0):
self.vertices = vertices
self.faces = faces
self.n = n
self.level_to_optimize = level_to_optimize
initial_guess = np.array([0.5,0]) + np.random.rand(1,2)/10
res = minimize(self.f,initial_guess)
a,b = res.x
c = (1-2*(a+b))/4
self.model = SWF(Trimesh(self.vertices,self.faces,ALPHA=a,BETA=b,GAMMA=c), n=self.n)
def f(self, coeffs):
ALPHA, BETA = coeffs
GAMMA = (1-2*(ALPHA+BETA))/4
mesh = Trimesh(self.vertices,self.faces,ALPHA=ALPHA,BETA=BETA,GAMMA=GAMMA)
model = SWF(mesh, n=self.n)
return cost(model,1,1,self.level_to_optimize)