Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7182551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:47:38+00:00 2026-05-28T17:47:38+00:00

Where can I find some good tutorials with examples with free data, on how

  • 0

Where can I find some good tutorials with examples with free data, on how to implement metaheuristics algorithms in R ?

I am asking this because I found lots of resources on how to do it, however I am facing big problems on moving from the theory to implement it.

The Book Essentials of Metaheuristics (by Professor Sean Luke) is a great book to start, however for people with a limited programming background and no experience with algorithms, it’s hard to implement them without some “real examples” with data, etc

Picking up an example from the Book Essentials of Metaheuristics (Page 16):

Algorithm 5 Steepest Ascent Hill-Climbing
1: n ← number of tweaks desired to sample the gradient
2: S ← some initial candidate solution
3: repeat
4: R ← Tweak(Copy(S))
5: for n − 1 times do
6: W ← Tweak(Copy(S))
7: if Quality(W) > Quality(R) then
8: R ← W
9: if Quality(R) > Quality(S) then
10: S ← R
11: until S is the ideal solution or we have run out of time
12: return S

I would like to have something that would after give me an example using real data.
I am looking for something like this.

I’ve seen many questions concerning specific algorithms (like GA) and maybe I am duplicating questions that already exist but I did not found this question in particular, but if this is duplicated please warn me.

Other languages like python would also help (e.g. any language similar to R).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:47:39+00:00Added an answer on May 28, 2026 at 5:47 pm

    I’m not familiar with metaheuristics as a field, but the pseudocode as you’ve given it actually translates fairly easily into R syntax:

    # I never metaheuristic I didn't like
    metah <- function(S, quality, tweak, n, outer.limit, threshold)
    {
        outer.n <- 0
        repeat {
            outer.n <- outer.n + 1
            R <- tweak(S)
            for(i in seq_len(n - 1))
            {
                W <- tweak(S)
                if(quality(W) > quality(R))
                    R <- W
            }
            if(quality(R) > quality(S))
                S <- R
            if(quality(S) >= threshold || outer.n >= outer.limit)
                break
        }
        S
    }
    

    Now all you have to do is provide suitable functions for quality and tweak.

    For example, suppose we want to fit a linear regression. In this case, we have a vector of responses y, and a matrix of vectors X. The solution S would be the vector of candidate coefficients at each step, and the “quality” is the squared error loss: sum((y - yhat)^2). Note that here, the lower the quality, the better.

    For tweak, we might use a normal distribution of perturbations from the current solution S, with a user-specified covariance matrix.

    This can then be coded up as

    require(MASS) # for mvrnorm
    
    quality <- function(S, y, X)
    sum((y - X %*% S)^2)
    
    tweak <- function(S, sigma=rep(1, length(s))
    S + mvrnorm(length(S), 0, sigma)
    
    metah <- function(y, X, quality, tweak, n, outer.limit, threshold)
    {
        outer.n <- 0
        S <- rep(1, ncol(X))
        repeat {
            outer.n <- outer.n + 1
            R <- tweak(S)
            for(i in seq_len(n - 1))
            {
                W <- tweak(S)
                if(quality(W, y, X) < quality(R, y, X)) # note reversed comparison!
                    R <- W
            }
            if(quality(R, y, X) < quality(S, y, X))
                S <- R
            if(quality(S) <= threshold || outer.n >= outer.limit)
                break
        }
        S
    }
    

    Further improvements might be:

    1. Replace the inner loop for(i in ...) with vectorised code using *apply

    2. let the distribution of tweaks vary depending on the characteristics of the solution, instead of hard-coding it as above (in particular, sigma should vary based on the scale of your X variables)

    3. express threshold in terms of your progress toward a minimum, for example how far each candidate solution has moved from the previous iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where can I find some good documentation on data/element binding? My Google searches haven't
Where can I find some good pointers on best practices for running ASP.NET MVC
Were can I find some good Podcasts that talk about program with Delphi &
I am looking for: What JMX is. Where I can find some good JMX
Can anyone reccomend some good tutorials for ext js and adobe air? The ones
Do you know where i can find some code examples for the new GWT
I am trying to find some good tutorials that would show me to create
This is driving me crazy and I can't find any good resources to explain
Hopefully I can find some words of advice from somebody. Is it possible to
Do you know where I can find some practice SQL problems where I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.