julia

How to ask for second best solution to a MIP using JuMP

房东的猫 提交于 2020-06-14 04:06:54
问题 I have a Mixed Integer Programming problem. I can use JuMP to find the optimal solution. But how can I find the second best solution? Or the third-best etc. This potentially might be another equally optimal solution, or it might be a worse solution, or it might be :Infeasible -- there might be no most solutions. I know for a TSP-like problem, I can find additional solutions by progressively removing links that are on the optimal path (I.e setting the distances between some of the cities to be

Generic function for stripping `LineNumberNode` in `Expr`(should be able to deal with :macrocalls)?

橙三吉。 提交于 2020-06-12 04:07:51
问题 Is there a build-in Julia function for stripping LineNumberNode in Expr ? especially for macrocalls: julia> ex = :(@foo 1) :(#= REPL[5]:1 =# @foo 1) julia> dump(ex) Expr head: Symbol macrocall args: Array{Any}((3,)) 1: Symbol @foo 2: LineNumberNode line: Int64 1 file: Symbol REPL[5] 3: Int64 1 Tried MacroTools.striplines , but julia> ex = :(@foo 1+1) :(#= REPL[7]:1 =# @foo 1 + 1) julia> MacroTools.striplines(ex) |> dump Expr head: Symbol macrocall args: Array{Any}((3,)) 1: Symbol @foo 2:

Generic function for stripping `LineNumberNode` in `Expr`(should be able to deal with :macrocalls)?

馋奶兔 提交于 2020-06-12 04:07:45
问题 Is there a build-in Julia function for stripping LineNumberNode in Expr ? especially for macrocalls: julia> ex = :(@foo 1) :(#= REPL[5]:1 =# @foo 1) julia> dump(ex) Expr head: Symbol macrocall args: Array{Any}((3,)) 1: Symbol @foo 2: LineNumberNode line: Int64 1 file: Symbol REPL[5] 3: Int64 1 Tried MacroTools.striplines , but julia> ex = :(@foo 1+1) :(#= REPL[7]:1 =# @foo 1 + 1) julia> MacroTools.striplines(ex) |> dump Expr head: Symbol macrocall args: Array{Any}((3,)) 1: Symbol @foo 2:

Is it possible to sort a dictionary in Julia?

泄露秘密 提交于 2020-05-12 11:14:14
问题 I have created a dictionary out of two arrays using zip() like list1 = [1,2,3,4,5] list2 = [6,7,8,9,19] dictionary1 = Dict(zip(list1,list2)) Now i want to sort this dictionary by key(list1) or by list2 . Can somebody show me a way or function, how to realize it? 回答1: Sort also takes a by keyword, which means you can do: julia> sort(collect(dictionary1), by=x->x[2]) 5-element Array{Tuple{Int64,Int64},1}: (1,6) (2,7) (3,8) (4,9) (5,19) Also note that there is a SortedDict in DataStructures.jl,

写一手漂亮的代码,走向极致的编程 一、代码运行时间分析

这一生的挚爱 提交于 2020-04-28 04:35:25
前言 写一手漂亮的代码,何谓漂亮的代码?对我来说大概有这么几点: 写法符合规范(如:该空格的地方打上空格,该换行的地方换行,名命方式符合规范等等) 简洁且可读性高(能十行代码实现并且让人容易看懂的绝不写十一行,对经常重复出现的代码段落进行封装) 性能高(如:运行时间尽可能短,运行时所用内存尽可能少) 要实现以上目标,自然就要对代码进行优化,说到代码的优化,自然而然就会想到对算法时间复杂度进行优化,比如我要实现一个在有序数组中查找一个数,最容易想到的就是遍历一遍 O(n) 的复杂度,优化一下自然是使用二分, O(logn) 的复杂度。如果这段代码在我们的程序中会经常被调用,那么,通过这算法上的优化,我们的程序性能自然而然的会有很高的提升。 但是,有时候会发现,已经对算法进行优化了,程序的性能(如运行时间、内存占用等)仍然不能达到预期,那么,这时候该如何对我们的代码进行进一步的优化呢? 这篇文章将以 Python 为例进行介绍 先来段代码 这里,我将通过使用 Julia 分形的代码来进行。 Julia 集合,由式 \(f_c(z) = z ^2 + c\) 进行反复迭代到。 对于固定的复数 c ,取某一 z 值,可以得到序列 \(z_0, f_c(z_0), f_c(f_c(z_0)), ...\) 这一序列可能发散于无穷大或处于某一范围之内并收敛于某一值,我们将使其不扩散的 z

Is there anyway to reset the current working directory in Julia?

与世无争的帅哥 提交于 2020-04-13 07:41:12
问题 Suppose the current working directory is C:\ (the directory where the .jl file is saved), and then I switch the cwd to some subfolders to perform some tasks. Is there anyway of directly resetting the cwd back to C:\ after that, i.e. the initial cwd? Or alternatively, is there anyway of locating the directory where the .jl file being run is located, independent of the current working directory? (Without saving the cwd as a variable beforehand) 回答1: You can use the do keyword together with the

Difference between Array and Vector

梦想与她 提交于 2020-04-13 07:34:53
问题 Is there a difference between Array and Vector ? typeof(Array([1,2,3])) Vector{Int64} typeof(Vector([1,2,3])) Vector{Int64} Both seem to create the same thing, but they are not the same: Array == Vector false Array === Vector false So, what is actually the difference? 回答1: The difference is that Vector is a 1-dimensional Array , so when you write e.g. Vector{Int} it is a shorthand to Array{Int, 1} : julia> Vector{Int} Array{Int64,1} When you call constructors Array([1,2,3]) and Vector([1,2,3]

In what way(s) can I benchmark a Julia function?

我只是一个虾纸丫 提交于 2020-04-12 11:00:46
问题 Background I've self-taught myself machine learning and have recently started delving into the Julia Machine Learning Ecosystem. Coming from a python background and having some Tensorflow and OpenCV/skimage experience, I want to benchmark Julia ML libraries (Flux/JuliaImages) against its counterparts to see how fast or slow it really performs CV (any) task(s) and to decide if I should shift to using Julia. I know how to get the time taken to execute a function in python using timeit module

In what way(s) can I benchmark a Julia function?

試著忘記壹切 提交于 2020-04-12 11:00:39
问题 Background I've self-taught myself machine learning and have recently started delving into the Julia Machine Learning Ecosystem. Coming from a python background and having some Tensorflow and OpenCV/skimage experience, I want to benchmark Julia ML libraries (Flux/JuliaImages) against its counterparts to see how fast or slow it really performs CV (any) task(s) and to decide if I should shift to using Julia. I know how to get the time taken to execute a function in python using timeit module

[翻译] Scalene: 一个 Python 的高性能 CPU 内存分析器

那年仲夏 提交于 2020-04-12 07:31:29
原文标题:scalene: a high-performance CPU and memory profiler for Python 原文链接: https:// github.com/emeryberger/ scalene/blob/master/README.md Scalene: 一个 Python 的高性能 CPU 内存分析器 by Emery Berger 关于 Scalene Scalene 是一个 Python 的高性能 CPU 和 内存分析器,它可以做到很多其他Python分析器不能做到的事情。它在能提供更多详细信息的同时,比其他的分析器要快几个数量级。 Scalene 是 很快的 。 它使用采样的方式而不是直接测量或者依靠Python的追踪工具。它的开销一般不超过10-20% (通常更少)。 Scalene 是 精确的 。和大部分其他的Python分析器不同,Scalene 在 行级别 下执行CPU分析,在你的程序中指出对应代码行的执行时间。和大多数分析器所返回的功能级分析结果相比,这种程度的细节可能会更有用。 Scalane 可以区分在Python中运行的时间和在native代码(包括库)中花费的时间。大多数的Python程序员并不会去优化native代码(通常在Python实现中或者所依赖的外部库),所以区分这两种运行时间