- 
                Notifications
    You must be signed in to change notification settings 
- Fork 22
GPR #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            MarlaJahari
  wants to merge
  9
  commits into
  xKDR:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
MarlaJahari:gpr
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    GPR #119
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            9 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d7ae662
              
                add test function
              
              
                 eebbc41
              
                add gpr functions
              
              
                 4f00084
              
                add gpr functions
              
              
                 70e12ca
              
                Delete launch.json
              
              
                MarlaJahari 3298371
              
                Added test cases.
              
              
                 2dae775
              
                Merge branch 'gpr' of github.com:MarlaJahari/CRRao.jl into gpr
              
              
                 0035598
              
                Update src/CRRao.jl
              
              
                MarlaJahari 8e7dbda
              
                Added test cases for GPR
              
              
                 f706cf4
              
                Merge branch 'gpr' of github.com:MarlaJahari/CRRao.jl into gpr
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
|  | ||
| """ | ||
| ```julia | ||
|  | ||
| fit(formula, data::DataFrame, modelClass::GaussianProcessesRegression, IndexVar, mean, kern::Kernel, | ||
| DistanceClass::Euclidean) | ||
| ``` | ||
|  | ||
| Fit a Gaussian Process Regression model on the input data with a Gaussian Process prior and user-specific mean and kernel functions. | ||
|  | ||
| #Example | ||
|  | ||
| ```julia-repl | ||
|  | ||
| julia> using CRRao, RDatasets, StatsModels, StatsPlots, GaussianProcesses, Distances | ||
| julia> df = dataset("datasets", "mtcars") | ||
| 32×12 DataFrame | ||
| Row │ Model MPG Cyl Disp HP DRat WT QSec VS AM Gear Carb | ||
| │ String31 Float64 Int64 Float64 Int64 Float64 Float64 Float64 Int64 Int64 Int64 Int64 | ||
| ─────┼────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| 1 │ Mazda RX4 21.0 6 160.0 110 3.9 2.62 16.46 0 1 4 4 | ||
| 2 │ Mazda RX4 Wag 21.0 6 160.0 110 3.9 2.875 17.02 0 1 4 4 | ||
| ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ | ||
| 31 │ Maserati Bora 15.0 8 301.0 335 3.54 3.57 14.6 0 1 5 8 | ||
| 32 │ Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 1 1 4 2 | ||
| 28 rows omitted | ||
|  | ||
| julia> container=fit(@formula(MPG ~0+ HP),df,GaussianProcessesRegression(),[:MPG, :HP],MeanZero(), SE(0.0,0.0),Euclidean()) | ||
|  | ||
| Formula: MPG ~ 0 + HP | ||
| Link: CRRao.Identity(CRRao.Identity_Link) | ||
| Chain: GP Exact object: | ||
| Dim = 1 | ||
| Number of observations = 32 | ||
| Mean function: | ||
| Type: MeanZero, Params: Float64[] | ||
| Kernel: | ||
| Type: SEIso{Float64}, Params: [5.464908573213355, 3.3936838718120708] | ||
|         
                  MarlaJahari marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| Input observations = | ||
| [110.0 110.0 … 335.0 109.0] | ||
| Output observations = [21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2 … 15.2, 13.3, 19.2, 27.3, 26.0, 30.4, 15.8, 19.7, 15.0, 21.4] | ||
| Variance of observation noise = 9.667961411202336 | ||
| Marginal Log-Likelihood = -89.745 | ||
| julia> plot(container.chain) | ||
| ``` | ||
| """ | ||
| function fit(formula, | ||
| data::DataFrame, | ||
| modelClass::GaussianProcessesRegression, | ||
| IndexVar, | ||
| mean, | ||
| kern::Kernel, | ||
| DistanceClass::Euclidean) | ||
|  | ||
| formula = apply_schema(formula, schema(formula, data), RegressionModel) | ||
| select!(data, IndexVar) | ||
| y, X = modelcols(formula, data) | ||
| logObsNoise = -1.0 | ||
| gp = GP(X', y, mean, kern, logObsNoise) | ||
| optimize!(gp) | ||
| return BayesianRegression(:GaussianProcessesRegression, gp, formula) | ||
|  | ||
| end | ||
|  | ||
| """ | ||
|  | ||
| ```julia | ||
|  | ||
| fit(formula, data::DataFrame, modelClass::GaussianProcessesRegression, IndexVar, mean | ||
| DistanceClass::Euclidean) | ||
| ``` | ||
|  | ||
| Fit a Gaussian Process Regression model on the input data with a Gaussian Process prior. The Zero Mean and Squared Exponential kernel function is implemented by default. | ||
|  | ||
| #Example | ||
|  | ||
| ```julia-repl | ||
| julia> using CRRao, RDatasets, StatsModels, StatsPlots, GaussianProcesses, Distances | ||
|  | ||
| julia> df = dataset("datasets", "mtcars") | ||
| 32×12 DataFrame | ||
| Row │ Model MPG Cyl Disp HP DRat WT QSec VS AM Gear Carb | ||
| │ String31 Float64 Int64 Float64 Int64 Float64 Float64 Float64 Int64 Int64 Int64 Int64 | ||
| ─────┼────────────────────────────────────────────────────────────────────────────────────────────────────────── | ||
| 1 │ Mazda RX4 21.0 6 160.0 110 3.9 2.62 16.46 0 1 4 4 | ||
| 2 │ Mazda RX4 Wag 21.0 6 160.0 110 3.9 2.875 17.02 0 1 4 4 | ||
| ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ | ||
| 31 │ Maserati Bora 15.0 8 301.0 335 3.54 3.57 14.6 0 1 5 8 | ||
| 32 │ Volvo 142E 21.4 4 121.0 109 4.11 2.78 18.6 1 1 4 2 | ||
| 28 rows omitted | ||
|  | ||
| julia> container=fit(@formula(MPG ~0+ HP),df,GaussianProcessesRegression(),[:MPG, :HP],Euclidean()) | ||
|  | ||
| Formula: MPG ~ 0 + HP | ||
| Link: CRRao.Identity(CRRao.Identity_Link) | ||
| Chain: GP Exact object: | ||
| Dim = 1 | ||
| Number of observations = 32 | ||
| Mean function: | ||
| Type: MeanZero, Params: Float64[] | ||
| Kernel: | ||
| Type: SEIso{Float64}, Params: [5.464908573213355, 3.3936838718120708] | ||
| Input observations = | ||
| [110.0 110.0 … 335.0 109.0] | ||
| Output observations = [21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2 … 15.2, 13.3, 19.2, 27.3, 26.0, 30.4, 15.8, 19.7, 15.0, 21.4] | ||
| Variance of observation noise = 9.667961411202336 | ||
| Marginal Log-Likelihood = -89.745 | ||
|  | ||
|  | ||
|  | ||
| julia> plot(container.chain) | ||
| ``` | ||
| """ | ||
|  | ||
|  | ||
| function fit(formula, | ||
| data::DataFrame, | ||
| modelClass::GaussianProcessesRegression, | ||
| IndexVar, | ||
| DistanceClass::Euclidean) | ||
|  | ||
| formula = apply_schema(formula, schema(formula, data), RegressionModel) | ||
| select!(data, IndexVar) | ||
| y, X = modelcols(formula, data) | ||
| logObsNoise = -1.0 | ||
| mean= MeanZero() | ||
| kern=SE(0.0,0.0) | ||
| gp = GP(X', y, mean, kern, logObsNoise) | ||
| optimize!(gp) | ||
| return BayesianRegression(:GaussianProcessesRegression, gp, formula) | ||
|  | ||
| end | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| mtcars = dataset("datasets", "mtcars") | ||
|  | ||
| CRRao.set_rng(StableRNG(123)) | ||
| model = fit(@formula(MPG ~ 0 + HP), mtcars, GaussianProcessesRegression(), [:MPG, :HP], MeanZero(), SE(0.0, 0.0), Euclidean()) | ||
|  | ||
| @test get_params(model.chain)[2:3] ≈ [5.464908573213355, 3.3936838718120708] | ||
| @test noise_variance(model.chain) ≈ 9.667961411202336 | ||
| @test model.chain.target ≈ -89.74473360543863 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.