Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
6af6574d
Commit
6af6574d
authored
Mar 16, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added implementation of cvoptimizer
parent
9b812b92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
optimizers.pyx
alphamind/cython/optimizers.pyx
+80
-0
No files found.
alphamind/cython/optimizers.pyx
View file @
6af6574d
...
...
@@ -54,6 +54,86 @@ cdef class LPOptimizer:
return np.array(self.cobj.xValue())
cdef extern from "tvoptimizer.hpp" namespace "pfopt":
cdef cppclass TVOptimizer:
TVOptimizer(int,
double*,
double*,
double*,
double*,
int,
double*,
double*,
double*,
double,
double) except +
vector[double] xValue()
double feval()
int status()
cdef class CVOptimizer:
cdef TVOptimizer* cobj
cdef int n
cdef int m
def __cinit__(self,
double[:] expected_return,
cnp.ndarray[double, ndim=2] cov_matrix,
double[:] lbound,
double[:] ubound,
cnp.ndarray[double, ndim=2] cons_matrix=None,
double[:] clbound=None,
double[:] cubound=None,
double target_low=0.0,
double target_high=1.0):
self.n = lbound.shape[0]
self.m = 0
cdef double[:] cov = cov_matrix.flatten(order='C')
cdef double[:] cons
if cons_matrix is not None:
self.m = cons_matrix.shape[0]
cons = cons_matrix.flatten(order='C');
self.cobj = new TVOptimizer(self.n,
&expected_return[0],
&cov[0],
&lbound[0],
&ubound[0],
self.m,
&cons[0],
&clbound[0],
&cubound[0],
target_low,
target_high)
else:
self.cobj = new TVOptimizer(self.n,
&expected_return[0],
&cov[0],
&lbound[0],
&ubound[0],
0,
NULL,
NULL,
NULL,
target_low,
target_high)
def __dealloc__(self):
del self.cobj
def feval(self):
return self.cobj.feval()
def x_value(self):
return np.array(self.cobj.xValue())
def status(self):
return self.cobj.status()
cdef extern from "mvoptimizer.hpp" namespace "pfopt":
cdef cppclass MVOptimizer:
MVOptimizer(int,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment