Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kmeans
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
dario.genga
kmeans
Commits
c1db1b96
Commit
c1db1b96
authored
2 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add option to define output path
parent
f3cb8734
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
kmeans.c
+0
-1
0 additions, 1 deletion
kmeans.c
kmeans.h
+0
-2
0 additions, 2 deletions
kmeans.h
main.c
+22
-9
22 additions, 9 deletions
main.c
with
23 additions
and
12 deletions
.gitignore
+
1
−
0
View file @
c1db1b96
...
...
@@ -79,5 +79,6 @@ dkms.conf
# Custom gitignore for project
main
output_data.txt
cmake-build-debug
.idea
\ No newline at end of file
This diff is collapsed.
Click to expand it.
kmeans.c
+
0
−
1
View file @
c1db1b96
...
...
@@ -4,7 +4,6 @@
#include
"kmeans.h"
/// Create empty clusters for the universe
/// \param universe The universe who contains the cluster to create.
void
initialize_clusters_array
(
kmeans
*
universe
)
{
...
...
This diff is collapsed.
Click to expand it.
kmeans.h
+
0
−
2
View file @
c1db1b96
...
...
@@ -11,8 +11,6 @@
#include
"files_utils.h"
#include
"values_utils.h"
#define REQUIRED_FULL_ARGS 4
#define ONLY_SOURCE_PATH_ARG 2
#define LINE_INDEX_DIMENSIONS 0
#define LINE_INDEX_CLUSTER 1
#define LINE_INDEX_CONTENT 2
...
...
This diff is collapsed.
Click to expand it.
main.c
+
22
−
9
View file @
c1db1b96
...
...
@@ -6,15 +6,17 @@
#include
<time.h>
#include
"kmeans.h"
#define REQUIRED_FULL_ARGS
4
#define REQUIRED_FULL_ARGS
5
#define ONLY_SOURCE_PATH_ARG 2
#define FILE_OUTPUT "./output_data.txt"
#define ONLY_SOURCE_AND_OUTPUT_PATH_ARGS 3
#define DEFAULT_FILE_OUTPUT "./output.txt"
kmeans
*
init_frm_cmd_arguments
(
int
argc
,
char
*
argv
[])
{
kmeans
*
init_frm_cmd_arguments
(
int
argc
,
char
*
argv
[]
,
char
*
output_file
)
{
kmeans
*
universe
;
int
k
;
int
dimensions
;
char
data_path
[
256
];
char
output
[
256
];
int
*
data_length
=
malloc
(
sizeof
(
int
));
point
**
data
;
...
...
@@ -26,18 +28,25 @@ kmeans *init_frm_cmd_arguments(int argc, char *argv[]) {
scanf
(
"%d"
,
&
dimensions
);
printf
(
"Path to data (comma separator) : "
);
scanf
(
"%s"
,
data_path
);
printf
(
"Output : "
);
scanf
(
"%s"
,
output
);
}
// Create the universe with only our file
else
if
(
argc
==
ONLY_SOURCE_PATH_ARG
)
{
else
if
(
argc
==
ONLY_SOURCE_PATH_ARG
||
argc
==
ONLY_SOURCE_AND_OUTPUT_PATH_ARGS
)
{
strcpy
(
data_path
,
argv
[
1
]);
universe
=
kmeans_create_empty
();
read_custom_data_source
(
universe
,
data_path
);
if
(
argc
==
ONLY_SOURCE_PATH_ARG
)
strcpy
(
output
,
DEFAULT_FILE_OUTPUT
);
else
strcpy
(
output
,
argv
[
2
]);
}
// Set the number of dimensions, clusters and path to data
else
if
(
argc
==
REQUIRED_FULL_ARGS
)
{
dimensions
=
atoi
(
argv
[
1
]);
k
=
atoi
(
argv
[
2
]);
strcpy
(
data_path
,
argv
[
3
]);
strcpy
(
output
,
argv
[
4
]);
}
// Bad number of arguments
else
{
...
...
@@ -48,15 +57,17 @@ kmeans *init_frm_cmd_arguments(int argc, char *argv[]) {
// Display instructions
printf
(
"you must start the program without arguments or with one of the following format :
\n
"
);
printf
(
"main <number of dimensions> <number of cluster> <path_to_data_source>
\n
"
);
printf
(
"
or
\n
"
);
printf
(
"main <number of dimensions> <number of cluster> <path_to_data_source>
<output_path>
\n
"
);
printf
(
"
main <path_to_custom_data_source> <output_path>
\n
"
);
printf
(
"main <path_to_custom_data_source>
\n
"
);
exit
(
EXIT_SUCCESS
);
}
// Save the output file path
strcpy
(
output_file
,
output
);
// Create the universe
if
(
argc
!=
ONLY_SOURCE_PATH_ARG
)
{
if
(
argc
!=
ONLY_SOURCE_PATH_ARG
&&
argc
!=
ONLY_SOURCE_AND_OUTPUT_PATH_ARGS
)
{
data
=
read_data
(
data_path
,
dimensions
,
data_length
);
universe
=
kmeans_create
(
k
,
dimensions
,
data
,
*
data_length
);
}
...
...
@@ -67,15 +78,17 @@ kmeans *init_frm_cmd_arguments(int argc, char *argv[]) {
int
main
(
int
argc
,
char
*
argv
[])
{
srand
(
time
(
NULL
));
char
output_file
[
256
];
// Initialize the universe
kmeans
*
universe
=
init_frm_cmd_arguments
(
argc
,
argv
);
kmeans
*
universe
=
init_frm_cmd_arguments
(
argc
,
argv
,
output_file
);
printf
(
"%s"
,
output_file
);
// Start the clustering
start_clustering
(
universe
);
// Output the result to a file
write_data_output
(
universe
,
FILE_OUTPUT
);
write_data_output
(
universe
,
output_file
);
// Free the universe and exit the program
destroy_universe
(
universe
);
...
...
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