Skip to content

Commit 48c72b5

Browse files
committed
Eigen solution with Number class to compile
1 parent 9b1e867 commit 48c72b5

6 files changed

Lines changed: 203 additions & 3 deletions

File tree

Programs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# OpenMind Neural Networks
2+
add_subdirectory(MathTool)

Programs/MathTool/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(this_target MathTool)
2+
project(${this_target})
3+
4+
find_package(OpenGL REQUIRED)
5+
find_package(GLUT REQUIRED)
6+
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
7+
8+
file(GLOB src *.cpp *.h)
9+
add_executable(${this_target} ${src})
10+
include_directories(${OpenMind_Incs})
11+
target_link_libraries(${this_target}
12+
${OPENGL_gl_LIBRARY}
13+
${OPENGL_glu_LIBRARY}
14+
${GLUT_glut_LIBRARY}
15+
${GLUT_cocoa_LIBRARY}
16+
omnn)

Programs/MathTool/main.cpp

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//
2+
// Created by Сергей Кривонос on 16.08.17.
3+
//
4+
5+
#include <GL/gl.h>
6+
#include <GL/glu.h>
7+
#include <GLUT/GLUT.h>
8+
#include <vector>
9+
10+
//int main()
11+
//{
12+
// auto hwnd = glutCreateWindow("MathTool");
13+
// //Frustum(-1, 1, -1, 1, 1, -1);
14+
// return 0;
15+
//}
16+
17+
GLfloat mat_red_diffuse[] = { 0.7, 0.7, 0.7, 1.0 };
18+
GLfloat mat_green_diffuse[] = { 0.0, 0.7, 0.1, .5 };
19+
GLfloat mat_blue_diffuse[] = { 0.0, 0.1, 0.7, 1.0 };
20+
GLfloat mat_yellow_diffuse[] = { 0.7, 0.8, 0.1, 1.0 };
21+
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
22+
GLfloat mat_shininess[] = { 100.0 };
23+
GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 };
24+
const int N = 16;
25+
GLfloat pts1[4][4][3], pts2[4][4][3];
26+
GLfloat pts3[4][4][3], pts4[4][4][3];
27+
28+
29+
30+
static void
31+
display(void)
32+
{
33+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
34+
glCallList(1);
35+
glFlush();
36+
}
37+
38+
int
39+
main(int argc, char **argv)
40+
{
41+
42+
43+
glutInit(&argc, argv);
44+
glutCreateWindow("x*y");
45+
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
46+
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
47+
glEnable(GL_LIGHTING);
48+
glEnable(GL_LIGHT0);
49+
glEnable(GL_DEPTH_TEST);
50+
glEnable(GL_AUTO_NORMAL);
51+
glEnable(GL_NORMALIZE);
52+
GLUnurbsObj * nurb = gluNewNurbsRenderer();
53+
gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 2.0);
54+
gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_POINT);
55+
56+
/* Build control points for NURBS mole hills. */
57+
int u, v;
58+
for(u=0; u<4; u++) {
59+
for(v=0; v<4; v++) {
60+
GLfloat x = u;
61+
GLfloat y = v;
62+
63+
/* Red. */
64+
pts1[u][v][0] = 2.0*((GLfloat)x);
65+
pts1[u][v][1] = 2.0*((GLfloat)y);
66+
pts1[u][v][2] = x*y;
67+
68+
/* Green. */
69+
pts2[u][v][0] = 2.0*((GLfloat)x - 3.);
70+
pts2[u][v][1] = 2.0*((GLfloat)y - 3.0);
71+
pts2[3-u][3-v][2] = (-x*y);
72+
73+
74+
/* Blue. */
75+
pts3[u][v][0] = 2.0*((GLfloat)x - 3.0);
76+
pts3[u][v][1] = 2.0*((GLfloat)y);
77+
pts3[3-u][v][2] = -x*y;
78+
79+
80+
/* Yellow. */
81+
pts4[u][v][0] = 2.0*((GLfloat)x);
82+
pts4[u][v][1] = 2.0*((GLfloat)y - 3.0);
83+
pts4[u][3-v][2] = x*(-y);
84+
}
85+
}
86+
// /* Stretch up red's far right corner. */
87+
// pts1[3][3][2] = 6;
88+
// /* Pull down green's near left corner a little. */
89+
// pts2[0][0][2] = -2;
90+
// /* Turn up meeting of four corners. */
91+
// pts1[0][0][2] = 1;
92+
// pts2[3][3][2] = 1;
93+
// pts3[3][0][2] = 1;
94+
// pts4[0][3][2] = 1;
95+
96+
glMatrixMode(GL_PROJECTION);
97+
98+
gluPerspective(105.0, 1.0, 2.0, 24.0);
99+
glMatrixMode(GL_MODELVIEW);
100+
glTranslatef(0.0, 0.0, -15.0);
101+
glRotatef(330.0, 1.0, 0.0, 0.0);
102+
103+
glNewList(1, GL_COMPILE);
104+
/* Render red hill. */
105+
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse);
106+
gluBeginSurface(nurb);
107+
gluNurbsSurface(nurb, 8, knots, 8, knots,
108+
4 * 3, 3, &pts1[0][0][0],
109+
4, 4, GL_MAP2_VERTEX_3);
110+
gluEndSurface(nurb);
111+
112+
/* Render green hill. */
113+
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green_diffuse);
114+
gluBeginSurface(nurb);
115+
gluNurbsSurface(nurb, 8, knots, 8, knots,
116+
4 * 3, 3, &pts2[0][0][0],
117+
4, 4, GL_MAP2_VERTEX_3);
118+
gluEndSurface(nurb);
119+
120+
/* Render blue hill. */
121+
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue_diffuse);
122+
gluBeginSurface(nurb);
123+
gluNurbsSurface(nurb, 8, knots, 8, knots,
124+
4 * 3, 3, &pts3[0][0][0],
125+
4, 4, GL_MAP2_VERTEX_3);
126+
gluEndSurface(nurb);
127+
128+
/* Render yellow hill. */
129+
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_yellow_diffuse);
130+
gluBeginSurface(nurb);
131+
gluNurbsSurface(nurb, 8, knots, 8, knots,
132+
4 * 3, 3, &pts4[0][0][0],
133+
4, 4, GL_MAP2_VERTEX_3);
134+
gluEndSurface(nurb);
135+
glEndList();
136+
137+
glutDisplayFunc(display);
138+
glutMainLoop();
139+
return 0; /* ANSI C requires main to return int. */
140+
}

omnn/extrapolator/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
lib(math)
1+
2+
3+
lib(math Eigen3 libeigen/eigen)

omnn/extrapolator/Extrapolator.h

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <limits>
1414
#include <limits.h>
1515
#include <type_traits>
16-
16+
#include "Expression.h"
17+
#include <Eigen/Dense>
1718
#include <boost/numeric/ublas/matrix.hpp>
1819
#include <boost/numeric/ublas/lu.hpp>
1920

@@ -26,13 +27,38 @@ namespace omnn::math {
2627
using extrapolator_base_matrix = boost::numeric::ublas::matrix<extrapolator_value_type>;
2728

2829

30+
31+
//Number det_fast(ublas::matrix<Number> matrix)
32+
//{
33+
// ublas::permutation_matrix<std::size_t> pivots(matrix.size1());
34+
//
35+
// auto isSingular = ublas::lu_factorize(matrix, pivots);
36+
// if (isSingular)
37+
// return static_cast<Number>(0);
38+
//
39+
// Number det = static_cast<Number>(1);
40+
// for (std::size_t i = 0; i < pivots.size(); ++i)
41+
// {
42+
// if (pivots(i) != i)
43+
// det *= static_cast<Number>(-1);
44+
//
45+
// det *= matrix(i, i);
46+
// }
47+
//
48+
// return det;
49+
//}
50+
51+
using extrapolator_base_matrix = Eigen::Matrix<Number, Eigen::Dynamic, Eigen::Dynamic>;
52+
53+
2954
class Extrapolator
3055
: public extrapolator_base_matrix
3156
{
3257
using base = extrapolator_base_matrix;
3358
using T = extrapolator_base_matrix::value_type;
3459

35-
using solution_t = typename ublas::matrix_vector_solve_traits<base, ublas::vector<T>>::result_type;
60+
//using solution_t = typename ublas::matrix_vector_solve_traits<base, ublas::vector<T>>::result_type;
61+
using solution_t = Eigen::Vector3f;
3662

3763
mutable solution_t solution;
3864

@@ -46,6 +72,18 @@ class Extrapolator
4672
solution_t Solve(const ublas::vector<T>& augment) const;
4773

4874
T Determinant() const;
75+
auto Solve(const ublas::vector<T>& augment){
76+
auto n = rows();
77+
extrapolator_base_matrix a(n, 1);
78+
for (int i = 0; i < n; ++i) {
79+
a(i)=augment[i];
80+
}
81+
// for(auto item : augment) {
82+
// a << item;
83+
// }
84+
auto solution = this->llt().solve(a);
85+
return solution.rhs();
86+
}
4987

5088
/**
5189
* If possible, make the matrix consistent

vcpkg.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"boost-test",
1919
"boost-thread",
2020
"boost-uuid",
21+
"eigen3",
22+
"freeglut",
2123
"leveldb",
2224
{
2325
"name": "vcpkg-cmake",

0 commit comments

Comments
 (0)