Binary genetic programming image classifier's fitness function Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Optimize iterative pixel blending functionFitness functionGenetic algorithm final stageFast way to find the most similar color in an arrayReading content of directory for each HTTP requestAn assignment algorithm in CInterpreter for an assembly language with variadic instructionsDenoise an image under extreme time pressureGenetic algorithm fitness function for schedulingHex Dump Utility in x86-64 Assembly: Version 1.1
Wu formula for manifolds with boundary
Is it a good idea to use CNN to classify 1D signal?
When coming out of haste, do attackers have advantage on you?
Can melee weapons be used to deliver Contact Poisons?
How to answer "Have you ever been terminated?"
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
How to compare two different files line by line in unix?
For a new assistant professor in CS, how to build/manage a publication pipeline
What is this building called? (It was built in 2002)
Find the length x such that the two distances in the triangle are the same
bold in theorem
How to react to hostile behavior from a senior developer?
Amount of permutations on an NxNxN Rubik's Cube
Ports Showing Closed/Filtered in Nmap Scans
What does "lightly crushed" mean for cardamon pods?
Delete nth line from bottom
Is it cost-effective to upgrade an old-ish Giant Escape R3 commuter bike with entry-level branded parts (wheels, drivetrain)?
On SQL Server, is it possible to restrict certain users from using certain functions, operators or statements?
Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?
What is the escape velocity of a neutron particle (not neutron star)
Dating a Former Employee
What does this Jacques Hadamard quote mean?
Irreducible of finite Krull dimension implies quasi-compact?
Is there a kind of relay only consumes power when switching?
Binary genetic programming image classifier's fitness function
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Optimize iterative pixel blending functionFitness functionGenetic algorithm final stageFast way to find the most similar color in an arrayReading content of directory for each HTTP requestAn assignment algorithm in CInterpreter for an assembly language with variadic instructionsDenoise an image under extreme time pressureGenetic algorithm fitness function for schedulingHex Dump Utility in x86-64 Assembly: Version 1.1
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I am trying to figure out how to improve my binary image genetic programming classifier's fitness. It takes images and classifies them if it has some feature X or not in it.
These are the main points:
- It takes an image and looks at the first 8 x 8 pixel values (called window).
- It saves these 8 x 8 values into an array and runs decodeIndividual on them.
- decodeIndividual simply runs the individual's function and retrieves the first and last registers. Last register is the scratchVariable that is updated per each window throughout an image.
- The first register is the main identifier per window and it adds it to the y_result which is kept for one image.
- When all the windows have been evaluated, y_result is compared to the ground truth and the difference is added to the error. Then the same steps are repeated for another image.
Heres the code:
float GeneticProgramming::evaluateIndividual(Individual individualToEvaluate)
float y_result = 0.0f;
float error = 0.0f;
for (int m = 0; m < number; m++)
int scratchVariable = SCRATCH_VAR;
for (int row = 0; row <= images[m].rows - WINDOW_SIZE; row += STEP)
for (int col = 0; col <= images[m].cols - WINDOW_SIZE; col += STEP)
int registers[NUMBER_OF_REGISTERS] = 0;
for (int i = 0; i < NUMBER_OF_REGISTERS-1; i++)
for (int y = 0; y < row + STEP; y++)
for (int x = 0; x < col + STEP; x++)
registers[i] = images[m].at<uchar>(y,x);
registers[NUMBER_OF_REGISTERS-1] = scratchVariable;
// we run individual on a separate small window of size 8x8
std::pair<float, float> answer = decodeIndividual(individualToEvaluate, registers);
y_result += answer.first;
scratchVariable = answer.second;
float diff = y_groundtruth - y_result;
// want to look at squared error
error += pow(diff, 2);
// restart the y_result per image
float y_result = 0.0f;
cout << "Done with individual " << individualToEvaluate.index << endl;
return error;
images is just a vector where I stored all of my images. I also added the decodeIndividual function which just looks at instructions and the given registers from the window and runs the list of instructions.
std::pair<float, float> GeneticProgramming::decodeIndividual(Individual individualToDecode, int *array)
for(int i = 0; i < individualToDecode.getSize(); i++) // MAX_LENGTH
Instruction currentInstruction = individualToDecode.getInstructions()[i];
float operand1 = array[currentInstruction.op1];
float operand2 = array[currentInstruction.op2];
float result = 0;
switch(currentInstruction.operation)
case 0: //+
result = operand1 + operand2;
break;
case 1: //-
result = operand1 - operand2;
break;
case 2: //*
result = operand1 * operand2;
break;
case 3: /// (division)
if (operand2 == 0)
result = SAFE_DIVISION_DEF;
break;
result = operand1 / operand2;
break;
case 4: // square root
if (operand1 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand1);
break;
case 5:
if (operand2 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand2);
break;
default:
cout << "Default" << endl;
break;
array[currentInstruction.reg] = result;
return std::make_pair(array[0], array[NUMBER_OF_REGISTERS-1]);
The problem is that I have:
- 6 grey scale images reduced to size 60 x 80
- The window size is 8 x 8
- Step is 2
- Number of registers is 65
Yet it takes over 3 seconds to evaluate these 6 incredibly small images. How do I improve my code? I would appreciate anyone pointing out some mistakes or at least providing some guidance. I am thinking of using threads to evaluate each individual separately.
c++ performance image genetic-algorithm
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I am trying to figure out how to improve my binary image genetic programming classifier's fitness. It takes images and classifies them if it has some feature X or not in it.
These are the main points:
- It takes an image and looks at the first 8 x 8 pixel values (called window).
- It saves these 8 x 8 values into an array and runs decodeIndividual on them.
- decodeIndividual simply runs the individual's function and retrieves the first and last registers. Last register is the scratchVariable that is updated per each window throughout an image.
- The first register is the main identifier per window and it adds it to the y_result which is kept for one image.
- When all the windows have been evaluated, y_result is compared to the ground truth and the difference is added to the error. Then the same steps are repeated for another image.
Heres the code:
float GeneticProgramming::evaluateIndividual(Individual individualToEvaluate)
float y_result = 0.0f;
float error = 0.0f;
for (int m = 0; m < number; m++)
int scratchVariable = SCRATCH_VAR;
for (int row = 0; row <= images[m].rows - WINDOW_SIZE; row += STEP)
for (int col = 0; col <= images[m].cols - WINDOW_SIZE; col += STEP)
int registers[NUMBER_OF_REGISTERS] = 0;
for (int i = 0; i < NUMBER_OF_REGISTERS-1; i++)
for (int y = 0; y < row + STEP; y++)
for (int x = 0; x < col + STEP; x++)
registers[i] = images[m].at<uchar>(y,x);
registers[NUMBER_OF_REGISTERS-1] = scratchVariable;
// we run individual on a separate small window of size 8x8
std::pair<float, float> answer = decodeIndividual(individualToEvaluate, registers);
y_result += answer.first;
scratchVariable = answer.second;
float diff = y_groundtruth - y_result;
// want to look at squared error
error += pow(diff, 2);
// restart the y_result per image
float y_result = 0.0f;
cout << "Done with individual " << individualToEvaluate.index << endl;
return error;
images is just a vector where I stored all of my images. I also added the decodeIndividual function which just looks at instructions and the given registers from the window and runs the list of instructions.
std::pair<float, float> GeneticProgramming::decodeIndividual(Individual individualToDecode, int *array)
for(int i = 0; i < individualToDecode.getSize(); i++) // MAX_LENGTH
Instruction currentInstruction = individualToDecode.getInstructions()[i];
float operand1 = array[currentInstruction.op1];
float operand2 = array[currentInstruction.op2];
float result = 0;
switch(currentInstruction.operation)
case 0: //+
result = operand1 + operand2;
break;
case 1: //-
result = operand1 - operand2;
break;
case 2: //*
result = operand1 * operand2;
break;
case 3: /// (division)
if (operand2 == 0)
result = SAFE_DIVISION_DEF;
break;
result = operand1 / operand2;
break;
case 4: // square root
if (operand1 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand1);
break;
case 5:
if (operand2 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand2);
break;
default:
cout << "Default" << endl;
break;
array[currentInstruction.reg] = result;
return std::make_pair(array[0], array[NUMBER_OF_REGISTERS-1]);
The problem is that I have:
- 6 grey scale images reduced to size 60 x 80
- The window size is 8 x 8
- Step is 2
- Number of registers is 65
Yet it takes over 3 seconds to evaluate these 6 incredibly small images. How do I improve my code? I would appreciate anyone pointing out some mistakes or at least providing some guidance. I am thinking of using threads to evaluate each individual separately.
c++ performance image genetic-algorithm
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I am trying to figure out how to improve my binary image genetic programming classifier's fitness. It takes images and classifies them if it has some feature X or not in it.
These are the main points:
- It takes an image and looks at the first 8 x 8 pixel values (called window).
- It saves these 8 x 8 values into an array and runs decodeIndividual on them.
- decodeIndividual simply runs the individual's function and retrieves the first and last registers. Last register is the scratchVariable that is updated per each window throughout an image.
- The first register is the main identifier per window and it adds it to the y_result which is kept for one image.
- When all the windows have been evaluated, y_result is compared to the ground truth and the difference is added to the error. Then the same steps are repeated for another image.
Heres the code:
float GeneticProgramming::evaluateIndividual(Individual individualToEvaluate)
float y_result = 0.0f;
float error = 0.0f;
for (int m = 0; m < number; m++)
int scratchVariable = SCRATCH_VAR;
for (int row = 0; row <= images[m].rows - WINDOW_SIZE; row += STEP)
for (int col = 0; col <= images[m].cols - WINDOW_SIZE; col += STEP)
int registers[NUMBER_OF_REGISTERS] = 0;
for (int i = 0; i < NUMBER_OF_REGISTERS-1; i++)
for (int y = 0; y < row + STEP; y++)
for (int x = 0; x < col + STEP; x++)
registers[i] = images[m].at<uchar>(y,x);
registers[NUMBER_OF_REGISTERS-1] = scratchVariable;
// we run individual on a separate small window of size 8x8
std::pair<float, float> answer = decodeIndividual(individualToEvaluate, registers);
y_result += answer.first;
scratchVariable = answer.second;
float diff = y_groundtruth - y_result;
// want to look at squared error
error += pow(diff, 2);
// restart the y_result per image
float y_result = 0.0f;
cout << "Done with individual " << individualToEvaluate.index << endl;
return error;
images is just a vector where I stored all of my images. I also added the decodeIndividual function which just looks at instructions and the given registers from the window and runs the list of instructions.
std::pair<float, float> GeneticProgramming::decodeIndividual(Individual individualToDecode, int *array)
for(int i = 0; i < individualToDecode.getSize(); i++) // MAX_LENGTH
Instruction currentInstruction = individualToDecode.getInstructions()[i];
float operand1 = array[currentInstruction.op1];
float operand2 = array[currentInstruction.op2];
float result = 0;
switch(currentInstruction.operation)
case 0: //+
result = operand1 + operand2;
break;
case 1: //-
result = operand1 - operand2;
break;
case 2: //*
result = operand1 * operand2;
break;
case 3: /// (division)
if (operand2 == 0)
result = SAFE_DIVISION_DEF;
break;
result = operand1 / operand2;
break;
case 4: // square root
if (operand1 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand1);
break;
case 5:
if (operand2 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand2);
break;
default:
cout << "Default" << endl;
break;
array[currentInstruction.reg] = result;
return std::make_pair(array[0], array[NUMBER_OF_REGISTERS-1]);
The problem is that I have:
- 6 grey scale images reduced to size 60 x 80
- The window size is 8 x 8
- Step is 2
- Number of registers is 65
Yet it takes over 3 seconds to evaluate these 6 incredibly small images. How do I improve my code? I would appreciate anyone pointing out some mistakes or at least providing some guidance. I am thinking of using threads to evaluate each individual separately.
c++ performance image genetic-algorithm
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I am trying to figure out how to improve my binary image genetic programming classifier's fitness. It takes images and classifies them if it has some feature X or not in it.
These are the main points:
- It takes an image and looks at the first 8 x 8 pixel values (called window).
- It saves these 8 x 8 values into an array and runs decodeIndividual on them.
- decodeIndividual simply runs the individual's function and retrieves the first and last registers. Last register is the scratchVariable that is updated per each window throughout an image.
- The first register is the main identifier per window and it adds it to the y_result which is kept for one image.
- When all the windows have been evaluated, y_result is compared to the ground truth and the difference is added to the error. Then the same steps are repeated for another image.
Heres the code:
float GeneticProgramming::evaluateIndividual(Individual individualToEvaluate)
float y_result = 0.0f;
float error = 0.0f;
for (int m = 0; m < number; m++)
int scratchVariable = SCRATCH_VAR;
for (int row = 0; row <= images[m].rows - WINDOW_SIZE; row += STEP)
for (int col = 0; col <= images[m].cols - WINDOW_SIZE; col += STEP)
int registers[NUMBER_OF_REGISTERS] = 0;
for (int i = 0; i < NUMBER_OF_REGISTERS-1; i++)
for (int y = 0; y < row + STEP; y++)
for (int x = 0; x < col + STEP; x++)
registers[i] = images[m].at<uchar>(y,x);
registers[NUMBER_OF_REGISTERS-1] = scratchVariable;
// we run individual on a separate small window of size 8x8
std::pair<float, float> answer = decodeIndividual(individualToEvaluate, registers);
y_result += answer.first;
scratchVariable = answer.second;
float diff = y_groundtruth - y_result;
// want to look at squared error
error += pow(diff, 2);
// restart the y_result per image
float y_result = 0.0f;
cout << "Done with individual " << individualToEvaluate.index << endl;
return error;
images is just a vector where I stored all of my images. I also added the decodeIndividual function which just looks at instructions and the given registers from the window and runs the list of instructions.
std::pair<float, float> GeneticProgramming::decodeIndividual(Individual individualToDecode, int *array)
for(int i = 0; i < individualToDecode.getSize(); i++) // MAX_LENGTH
Instruction currentInstruction = individualToDecode.getInstructions()[i];
float operand1 = array[currentInstruction.op1];
float operand2 = array[currentInstruction.op2];
float result = 0;
switch(currentInstruction.operation)
case 0: //+
result = operand1 + operand2;
break;
case 1: //-
result = operand1 - operand2;
break;
case 2: //*
result = operand1 * operand2;
break;
case 3: /// (division)
if (operand2 == 0)
result = SAFE_DIVISION_DEF;
break;
result = operand1 / operand2;
break;
case 4: // square root
if (operand1 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand1);
break;
case 5:
if (operand2 < 0)
result = SAFE_DIVISION_DEF;
break;
result = sqrt(operand2);
break;
default:
cout << "Default" << endl;
break;
array[currentInstruction.reg] = result;
return std::make_pair(array[0], array[NUMBER_OF_REGISTERS-1]);
The problem is that I have:
- 6 grey scale images reduced to size 60 x 80
- The window size is 8 x 8
- Step is 2
- Number of registers is 65
Yet it takes over 3 seconds to evaluate these 6 incredibly small images. How do I improve my code? I would appreciate anyone pointing out some mistakes or at least providing some guidance. I am thinking of using threads to evaluate each individual separately.
c++ performance image genetic-algorithm
c++ performance image genetic-algorithm
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 10 mins ago
200_success
131k17157422
131k17157422
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 4 hours ago
GabrieleGabriele
62
62
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Gabriele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Gabriele is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217630%2fbinary-genetic-programming-image-classifiers-fitness-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Gabriele is a new contributor. Be nice, and check out our Code of Conduct.
Gabriele is a new contributor. Be nice, and check out our Code of Conduct.
Gabriele is a new contributor. Be nice, and check out our Code of Conduct.
Gabriele is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217630%2fbinary-genetic-programming-image-classifiers-fitness-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown