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
6c148f53
Commit
6c148f53
authored
Nov 06, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests for base optimizer
parent
71c388ea
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
2 deletions
+63
-2
models.py
alphamind/data/dbmodel/models.py
+1
-1
__init__.py
alphamind/tests/cython/__init__.py
+0
-0
test_optimizers.py
alphamind/tests/cython/test_optimizers.py
+59
-0
test_suite.py
alphamind/tests/test_suite.py
+3
-1
No files found.
alphamind/data/dbmodel/models.py
View file @
6c148f53
...
...
@@ -1852,5 +1852,5 @@ class FactorCorrelation(Base):
if
__name__
==
'__main__'
:
from
sqlalchemy
import
create_engine
engine
=
create_engine
(
'mysql+mysqldb://root:
we083826
@localhost/alpha'
)
engine
=
create_engine
(
'mysql+mysqldb://root:
password
@localhost/alpha'
)
Base
.
metadata
.
create_all
(
engine
)
alphamind/tests/cython/__init__.py
0 → 100644
View file @
6c148f53
alphamind/tests/cython/test_optimizers.py
0 → 100644
View file @
6c148f53
# -*- coding: utf-8 -*-
"""
Created on 2017-11-1
@author: cheng.li
"""
import
unittest
import
numpy
as
np
from
alphamind.cython.optimizers
import
LPOptimizer
from
alphamind.cython.optimizers
import
QPOptimizer
class
TestOptimizers
(
unittest
.
TestCase
):
def
test_lpoptimizer
(
self
):
objective
=
np
.
array
([
1.
,
2.
])
lower_bound
=
np
.
array
([
0.
,
0.2
])
upper_bound
=
np
.
array
([
1.
,
0.8
])
optimizer
=
LPOptimizer
(
np
.
array
([[
1.
,
1.
,
1.
,
1.
]]),
lower_bound
,
upper_bound
,
objective
)
self
.
assertAlmostEqual
(
optimizer
.
feval
(),
1.2
)
np
.
testing
.
assert_array_almost_equal
(
optimizer
.
x_value
(),
[
0.8
,
0.2
])
def
test_mvoptimizer
(
self
):
objective
=
np
.
array
([
0.01
,
0.02
,
0.03
])
cov
=
np
.
array
([[
0.02
,
0.01
,
0.02
],
[
0.01
,
0.02
,
0.03
],
[
0.02
,
0.03
,
0.02
]])
ids_var
=
np
.
diag
([
0.01
,
0.02
,
0.03
])
cov
+=
ids_var
lbound
=
np
.
array
([
0.
,
0.
,
0.
])
ubound
=
np
.
array
([
0.4
,
0.4
,
0.5
])
cons
=
np
.
array
([[
1.
,
1.
,
1.
],
[
1.
,
0.
,
1.
]])
clbound
=
np
.
array
([
1.
,
0.3
])
cubound
=
np
.
array
([
1.
,
0.7
])
optimizer
=
QPOptimizer
(
objective
,
cov
,
lbound
,
ubound
,
cons
,
clbound
,
cubound
)
# check against matlab result
np
.
testing
.
assert_array_almost_equal
(
optimizer
.
x_value
(),
[
0.1996
,
0.3004
,
0.5000
],
4
)
if
__name__
==
'__mai__'
:
unittest
.
main
()
alphamind/tests/test_suite.py
View file @
6c148f53
...
...
@@ -32,6 +32,7 @@ from alphamind.tests.execution.test_naiveexecutor import TestNaiveExecutor
from
alphamind.tests.execution.test_thresholdexecutor
import
TestThresholdExecutor
from
alphamind.tests.execution.test_targetvolexecutor
import
TestTargetVolExecutor
from
alphamind.tests.execution.test_pipeline
import
TestExecutionPipeline
from
alphamind.tests.cython.test_optimizers
import
TestOptimizers
if
__name__
==
'__main__'
:
...
...
@@ -55,6 +56,7 @@ if __name__ == '__main__':
TestNaiveExecutor
,
TestThresholdExecutor
,
TestTargetVolExecutor
,
TestExecutionPipeline
],
TestExecutionPipeline
,
TestOptimizers
],
alpha_logger
)
runner
.
run
()
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