Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
maths_optimisation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
philippe.montando
maths_optimisation
Commits
21033f5e
Commit
21033f5e
authored
3 years ago
by
sgegito
Browse files
Options
Downloads
Patches
Plain Diff
Erreur sur le merger, 1er groupe bizarre et 2eme groupe ok... why???
parent
dcf36e15
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opti.c
+42
-14
42 additions, 14 deletions
opti.c
opti.h
+1
-0
1 addition, 0 deletions
opti.h
with
43 additions
and
14 deletions
opti.c
+
42
−
14
View file @
21033f5e
#include
"opti.h"
int
LINE_POINTS
=
1000000
;
int
CLOUD_POINTS
=
3
00
;
int
CLOUD_POINTS
=
50
00
;
double
X_VALUE
=
0
.
000001
;
double
RANDOMNESS
=
0
.
01
;
// Learning rate
double
LR
=
0
.
000
0
1
;
double
LR
=
0
.
0001
;
// Error rate
double
ER
=
0
.
00000
0000
1
;
double
ER
=
0
.
000001
;
// La fonction pow() de math.h avait un problème aavec mon Makefile donc je l'ai refaite
// et puis après avoir résolu le problème (emplacement du -lm) afin de pouvoir utiliser
...
...
@@ -143,6 +143,24 @@ double cost2(double *a, double *b, double *new_a, double *new_b){
return
sqrt
(
popow
((
*
new_a
-
*
a
),
2
)
+
popow
((
*
new_b
-
*
b
),
2
));
}
Point
*
cloud_merger
(
Point
*
cloud_a
,
Point
*
cloud_b
,
bool
g3_here
){
int
cloud_size
;
if
(
!
g3_here
){
cloud_size
=
2
*
(
CLOUD_POINTS
)
/
3
;
}
else
{
cloud_size
=
CLOUD_POINTS
-
(
CLOUD_POINTS
/
3
);
}
Point
*
merged_cloud
=
(
Point
*
)
malloc
(
sizeof
(
Point
)
*
cloud_size
);
for
(
int
i
=
0
;
i
<
cloud_size
;
i
++
){
if
(
i
<
(
CLOUD_POINTS
/
3
)){
merged_cloud
[
i
]
=
cloud_a
[
i
];
}
else
{
merged_cloud
[
i
]
=
cloud_b
[
i
-
(
CLOUD_POINTS
/
3
)];
}
}
return
merged_cloud
;
}
int
main
(
void
){
srand
(
time
(
NULL
));
/*// Create a vector X = [0,1,2...99]
...
...
@@ -159,26 +177,36 @@ int main (void){
destroy_vector(&X);
*/
//Le a et le b calculé sur mon papier;
//
double a_init = 0.98902527076;
//
double b_init = -0.1537833935;
double
a_init
=
0
.
98902527076
;
double
b_init
=
-
0
.
1537833935
;
//Point* fluffy = cloud_test();
//
printf("\na
ini
tial = %f || b
ini
tial = %f\n", a_init, b_init);
printf
(
"
\n
a
op
ti
m
al = %f || b
op
ti
m
al = %f
\n
"
,
a_init
,
b_init
);
double
a
=
double_random
(
0
,
1
);
double
b
=
double_random
(
0
,
1
);
double
c
=
a
;
double
d
=
b
;
Point
*
fluffy
=
cloud2_5
(
&
a
,
&
b
);
printf
(
"
\n
a random initial = %f || b random initial = %f
\n
"
,
a
,
b
);
//gradient_descent_v4(&a, &b, fluffy);
//printf("\na trouvé = %f || b trouvé = %f\n", a, b);
Point
*
fluffy
=
cloud2_5
(
&
a_init
,
&
b_init
);
//printf("\na random initial = %f || b random initial = %f\n", a, b);
Point
**
cloud_slayer
=
cloud_splitter
(
fluffy
);
for
(
int
j
=
0
;
j
<
3
;
j
++
){
/*
for(int j=0;j<3;j++){
for(int i=0; i<CLOUD_POINTS/3;i++){
printf("\nG%d x = %g\nG%d y = %g\n", j+1,cloud_slayer[j][i].x , j+1, cloud_slayer[j][i].y);
}
}*/
Point
*
merged
=
cloud_merger
(
cloud_slayer
[
0
],
cloud_slayer
[
1
],
false
);
for
(
int
i
=
0
;
i
<
CLOUD_POINTS
*
2
/
3
;
i
++
){
printf
(
"
\n
MERGED : x=%g y=%g
\n
"
,
merged
[
i
].
x
,
merged
[
i
].
y
);
}
//gradient_descent_v4(&a, &b, fluffy);
gradient_descent_v4
(
&
a
,
&
b
,
merged
);
gradient_descent_v4
(
&
c
,
&
d
,
cloud_slayer
[
2
]);
printf
(
"
\n
a1 trouvé = %f || b1 trouvé = %f
\n
"
,
a
,
b
);
printf
(
"
\n
a2 trouvé = %f || b2 trouvé = %f
\n
"
,
c
,
d
);
//printf("\nx = %g\ny = %g\n",cloud_slayer[0][1].x , cloud_slayer[0][1].y);
printf
(
"
\n
done
\n
"
);
free
(
fluffy
);
free
(
merged
);
free
(
cloud_slayer
);
free
(
fluffy
);
printf
(
"
\n
done
\n
"
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
opti.h
+
1
−
0
View file @
21033f5e
...
...
@@ -33,5 +33,6 @@ double cost(double *a, double *b, Point* my_cloud);
void
gradient_descent_v4
(
double
*
a
,
double
*
b
,
Point
*
my_cloud
);
double
cost2
(
double
*
a
,
double
*
b
,
double
*
new_a
,
double
*
new_b
);
Point
**
cloud_splitter
(
Point
*
my_cloud
);
Point
*
cloud_merger
(
Point
*
cloud_a
,
Point
*
cloud_b
,
bool
g3_here
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment