julia

How to extract optimization problem matrices A,b,c using JuMP in Julia

孤人 提交于 2020-07-22 06:00:17
问题 I create an optimization model in Julia-JuMP using the symbolic variables and constraints e.g. below using JuMP using CPLEX # model Mod = Model(CPLEX.Optimizer) # sets I = 1:2; # Variables x = @variable( Mod , [I] , base_name = "x" ) y = @variable( Mod , [I] , base_name = "y" ) # constraints Con1 = @constraint( Mod , [i in I] , 2 * x[i] + 3 * y[i] <= 100 ) # objective ObjFun = @objective( Mod , Max , sum( x[i] + 2 * y[i] for i in I) ) ; # solve optimize!(Mod) I guess JuMP creates the problem

Implementing a sampler with array eltype

白昼怎懂夜的黑 提交于 2020-07-09 06:49:29
问题 Hooking into rand has been easier in the old days... I think I followed the description in the docs, but it doesn't seem to like a sampler returning an array: using Random struct Shell{N} r0::Float64 r1::Float64 end Base.eltype(::Type{Shell{N}}) where {N} = Array{Float64, N} function Random.rand(rng::Random.AbstractRNG, d::Random.SamplerTrivial{Shell{N}}) where {N} # ignore the correctness of the sampling algorithm for now :) shell = d[] Δ = shell.r1 - shell.r0 θ = Δ .* randn(N) r = shell.r0

Clone a function in Julia

此生再无相见时 提交于 2020-07-08 10:18:26
问题 I want to overwrite a function in Julia using its old definition. It seems the way to do this would be to clone the function and overwrite the original using the copy — something like the following. However, it appears deepcopy(f) just returns a reference to f , so this doesn't work. f(x) = x f_old = deepcopy(f) f(x) = 1 + f_old(x) How can I clone a function? Background: I'm interesting in writing a macro @override that allows me to override functions pointwise (or maybe even piecewise). fib

Is the order of Julia Sets and Dicts guaranteed to be stable across sessions, platforms and versions?

两盒软妹~` 提交于 2020-06-27 10:36:46
问题 I tried running the following code across multiple Julia REPL sessions, on MacOSX and Linux, and the outputs were always exactly the same (in the same order): julia> (Set([1, 2, 3, 4]), Dict(1=>2, 3=>4, 5=>6)) (Set([4, 2, 3, 1]), Dict(3 => 4,5 => 6,1 => 2)) Question: is this behavior guaranteed by the language, across sessions, platforms and versions, and for all hash-based collections? Notes: I understand that the output order may vary depending on the insertion order, especially if there

Is the order of Julia Sets and Dicts guaranteed to be stable across sessions, platforms and versions?

走远了吗. 提交于 2020-06-27 10:36:05
问题 I tried running the following code across multiple Julia REPL sessions, on MacOSX and Linux, and the outputs were always exactly the same (in the same order): julia> (Set([1, 2, 3, 4]), Dict(1=>2, 3=>4, 5=>6)) (Set([4, 2, 3, 1]), Dict(3 => 4,5 => 6,1 => 2)) Question: is this behavior guaranteed by the language, across sessions, platforms and versions, and for all hash-based collections? Notes: I understand that the output order may vary depending on the insertion order, especially if there

How to execute a Julia script step by step?

巧了我就是萌 提交于 2020-06-27 07:28:09
问题 Is there any way in Julia to execute an existing script step by step in REPL meanwhile being able to modify/plot arrays? (As in the case of Matlab debugging) Note: I am especially asking this for version 0.4 for which hopefully a new debugging system is being implemented. 回答1: You have a few options: The Debug package provides step-by-step debugging. It hasn't yet been updated for 0.4, however. Juno provides some nice functionality for executing specific lines, and includes integrated

Maximum of multiple images or arrays in Julia

旧时模样 提交于 2020-06-26 01:39:43
问题 I want to find a maximum of several images: load them into an array and find a maximum along first dimension. Python code for example: import cv2 import sys import numpy as np imgs_paths = sys.argv[1:] imgs = list(map(cv2.imread, imgs_paths)) imgs_arr = np.array(imgs, dtype=np.float32) imgs_max = np.max(imgs_arr, 0) What I did is the following: using Colors, Images function im_to_array(im) img_array = permutedims(channelview(im), (2,3,1)) img_array = Float32.(img_array) return img_array end

Maximum of multiple images or arrays in Julia

£可爱£侵袭症+ 提交于 2020-06-26 01:34:40
问题 I want to find a maximum of several images: load them into an array and find a maximum along first dimension. Python code for example: import cv2 import sys import numpy as np imgs_paths = sys.argv[1:] imgs = list(map(cv2.imread, imgs_paths)) imgs_arr = np.array(imgs, dtype=np.float32) imgs_max = np.max(imgs_arr, 0) What I did is the following: using Colors, Images function im_to_array(im) img_array = permutedims(channelview(im), (2,3,1)) img_array = Float32.(img_array) return img_array end

What is “setindex! not defined” error in julia?

烈酒焚心 提交于 2020-06-16 03:23:59
问题 When I run my code one error occurs with my code setindex! not defined for WeakRefStrings.StringArray{String,1} CSV File here. using CSV EVDdata =CSV.read(raw"wikipediaEVDdatesconverted.csv") EVDdata[end-9:end,:] And the Error Code is here rows, cols = size(EVDdata) for j =1:cols for i = 1:rows if !isdigit(string(EVDdata[i, j])[1]) EVDdata[i,j] = 0 end end end I am working with Julia 1.4.1 on Jupter Notebook 回答1: setindex!(collection, item, inds...) is the function that colection[inds...] =

What is “setindex! not defined” error in julia?

北城余情 提交于 2020-06-16 03:23:10
问题 When I run my code one error occurs with my code setindex! not defined for WeakRefStrings.StringArray{String,1} CSV File here. using CSV EVDdata =CSV.read(raw"wikipediaEVDdatesconverted.csv") EVDdata[end-9:end,:] And the Error Code is here rows, cols = size(EVDdata) for j =1:cols for i = 1:rows if !isdigit(string(EVDdata[i, j])[1]) EVDdata[i,j] = 0 end end end I am working with Julia 1.4.1 on Jupter Notebook 回答1: setindex!(collection, item, inds...) is the function that colection[inds...] =