Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

Change that: @everywhere function mutate(selectedplayers, positionvectorslist,…

  1. User

    Change that: @everywhere function mutate(selected_players, position_vectors_list, probability) selected_players_matrix = copy(selected_players)

    function select_random_player(idx_list, selected_players)
        while true
            random_idx = rand(idx_list)
            if ismissing(selected_players) || !(random_idx in selected_players)
                return random_idx
            end
        end
    end
    
    
    
    for i in 1:size(selected_players_matrix)[1]
        for pos_idx in 1:length(position_vectors_list)
            if rand() <= probability
                selected_players_matrix[i, pos_idx] = select_random_player(position_vectors_list[pos_idx],
                                                                           selected_players_matrix[i, :])
            end
        end
    end
    
    return selected_players_matrix
    

    end so it would fit a DataFrame with 1 column containing vectors.

  2. Assistant

    You can modify the function like below to make it fit a DataFrame with 1 column containing vectors:

    @everywhere function mutate(df, position_vectors_list, probability)
        selected_players_matrix = copy(df[!, 1])
    
        function select_random_player(idx_list, selected_players)
            while true
                random_idx = rand(idx_list)
                if ismissing(selected_players) || !(random_idx in selected_players)
                    return random_idx
                end
            end
        end
    
        for i in 1:length(selected_players_matrix)
            for pos_idx in 1:length(position_vectors_list)
                if rand() <= probability
                    selected_players_matrix[i][pos_idx] = select_random_player(position_vectors_list[pos_idx],
                                                                              selected_players_matrix[i])
                end
            end
        end
    
        df[!, 1] = selected_players_matrix
        return df
    end
    

    Now the function takes a DataFrame df as the first argument, and modifies it directly. Before running the loop, we copy the content of the first column in selected_players_matrix variable. And we replace the for-loop for loop for dimension/size of the matrix with just the length of selected_players_matrix array. Lastly, we modify the contents of the first column of df with the new contents of selected_players_matrix.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.