jeudi 1 septembre 2022

Bug in sklearn WhiteKernel: always returns zero

White Kernel, which should behave like this

k(x1, x2) = 0 if x1 != x2 else noies_level

is always returning zero:

from sklearn.gaussian_process import kernels
import numpy as np
import sklearn
print(kernels.WhiteKernel(noise_level=2.0)(np.array([[1.0]]), np.array([[1.0]])))
print(sklearn.__version__)

Result:

[[0.]]
1.1.1

I'm expecting nonzero result. What am I missing here?




How do I duplicate a random unique string from a user for Java?

I want to multiply a string value to be entered from the screen as many random uniques as the number of elements in the list I have. For example, the user will enter a company name on the screen, for example NIKE. Let's say I have phone numbers on the list. How can I generate unique values ​​such as NIKE1, NIKE2, NIKE3, NIKEW, NIKEW1 as much as the number of phone numbers(list size) for Java8?




How to make it so each enemy is given a random time difference?

My game variables

#Game rules
time = 1
time_passed = 0
complete_time = 400
enemy_timer = random.choice([1000,2000,3000])
finished_enemy = pygame.time.get_ticks()
enemies_alive = 0

My creation of enemies

#creating enemies 
    if time_passed < complete_time :
        if pygame.time.get_ticks() - finished_enemy > enemy_timer:
            r = random.randint(0, len(enemy_types) - 1)
            enemy = Enemy(enemy_health[r],enemy_animations[r], WINDOW_WIDTH - -10, WINDOW_HEIGHT - 260, 2) #gets arguments from enemy class and where they are(location)
            enemy_1 = Enemy(enemy_health[r],enemy_animations[r], WINDOW_WIDTH - -10, WINDOW_HEIGHT - 160, 1)
            enemy_2 = Enemy(enemy_health[r],enemy_animations[r], WINDOW_WIDTH - -10, WINDOW_HEIGHT - 60, 3)
            enemy_group.add(enemy,enemy_1,enemy_2)
            finished_enemy = pygame.time.get_ticks()
            #allows for increasing difficulty
            time_passed += enemy_health[r]
            print(time_passed)

Sorry for wording of the question as i dont know how to describe what i want in a sentence.

Anyway I have the code for randomizing three values for enemy_timer (1000,2000,3000) what it does is separate the images of my enemy by millisecond. I want it to affect enemy, enemy_1 and enemy_2 differently. Such as when i run enemy has 1000 enemy_2 has 3000 so on.




What Import Statements are need For Reverse? [closed]

What Import Statements are needed for the following?

  1. getRandomNum
  2. reverseDigits
  3. replaceLtr
  4. replaceString



Python is not identifying my input and comparing it to variable get [duplicate]

My variables aren't comparing to each other. Is it because it is in a class, or is there some other problem?

import random


def game():
    result = random.uniform(1, 10)
    get = input("I'm thinking of a number, 1-10")
    if get == result:
        print("GG, the number was" + result)
    game()
    if get != result:
        print("That wasn't my number. My number was" + result + "Let's try again.")
    game()
game()



remove an element from the back of a vector after shuffling it c++

so the purpose of the code is to shuffle a vector, then print a random number from the vector, and then delete that same number so it won't repeat. what I did is:

  1. there is an initialized vector called songs, first I used random_device to make a random func.
  2. I initialized an iterator to the back of the vector.
  3. I shuffled the vector
  4. Print
  5. remove the last element that I printed (after shuffling).

The problem is when I do songs.pop_back(); it removes the last element from the original vector and not from the shuffled one, so it makes numbers coming back that way. and I get an error.

code:

int getSong(int n, vector<int> songs, vector<int>::iterator iter) {
    random_device random;
    shuffle(songs.begin(), songs.end(), random);
    for (int j = 0; j < n; j++) {
        cout << songs[j] << " ";
    }
    iter = songs.end() -1 ;
    int song = *iter;
    iter--;
    return song;
}

int main() {

    vector<int> songs = { 1,2,3,4,5,6,7,8,9 };
    int n = songs.size();
    vector<int>::iterator iter;
    for (int i = 0; i < n; n--) {
        int l = getSong(n, songs, iter);
        cout << "The song number is:" << l << "\n" << endl;
        songs.pop_back();
    }

    return 0;
}

the output is: enter image description here

Thank you!




Problem in a generation of a random number with sample and rbinom in R

In my R code, while I generate a number with sample (1: edge_counter, 1) everything works fine but while I generate it with rbinom (1, i, p) the code doesn't work. What could be the problem?

Here is the code where i generate a graph following the Forrest Fire module, the random generation problem is when i generate a random x:

install.packages("igraph")

library(igraph)

par(mar=c(1,1,1,1))

#Number of node to add in the graph
num_nodes = 10

#Forward burning probability
p = 0.37

#Backward burning ratio
r = 0.32

#Parameters for the plot 
node_count <- rep(0, times = num_nodes)
edge_count <- rep(0, times = num_nodes)

g1 <- make_empty_graph(1)

for(i in 2:num_nodes)
{
  exit = 0
  visited_node <- rep(FALSE, times = i)
  g1 = add_vertices(g1,1)
  
  #orphans extention
  q = runif(1,0,1)
  if(q > 0.2)
  {   
    #chose an ambassador node 
    w <- sample(1:(vcount(g1)-1), 1)
  
    # connecting the ambassador with the node
    v = i; 
    g1 = add_edges(g1,c(v,w))
  
    # count number of node linked to the ambassador 
    edge_counter <- 0 
    for(h in 1: i)
    {
      if(g1[w, h] == 1 || g1[h, w] == 1)
      {
        edge_counter =  edge_counter + 1
      }
    }
    
    selected_node <- rep(FALSE, times = i)
   
    while(exit == 0)
    {
      x = sample(1:edge_counter, 1)
      #x = rbinom(1, i, p)

        # select x links incident to w choosing from among both out links and in links  
        j = 0
        while(j != x)
        {
          prob <- runif(1,0,1)
          random_node <- sample(1:i, 1) 
            
          if(selected_node[random_node] == FALSE)
          {
            #chose out-link
            if(prob < r) 
            {
              if(g1[w, random_node] == 1)
              {
                selected_node[random_node] = TRUE 
                j = j+1
              }
            }
            #chose in-link
            else 
            {
              if (g1[random_node, w] == 1) 
              {
                selected_node[random_node] = TRUE
                j = j+1
              }
            }
          }
        } 
        
        #v forms out-links to w1,...wx
        for(l in 1:i)
        {
          if((selected_node[l] == TRUE) && (l != v))
          {
            g1 = add_edges(g1,c(v,l))
          }
        }
        
        old_v <- v
        
        visited_node[v] = TRUE
        
        for(j in 1:i)
        {
          if ((selected_node[j] == TRUE) && (visited_node[v] == FALSE))
          {
            v <- j
            break
          }
        }
        
        if(old_v == v)
        {
          exit = 1  
        }
      }
    }
  
  #Node and edge count
  node_count[i] = gorder(g1)
  edge_count[i] = gsize(g1)
}

# number of nodes respect number of edges 
plot(node_count, edge_count, xlab = "Number of nodes", ylab = "Number of edges")

#graph plot 
plot(g1)