<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sayan Sinha on Medium]]></title>
        <description><![CDATA[Stories by Sayan Sinha on Medium]]></description>
        <link>https://medium.com/@americast?source=rss-6aae5c21a399------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tcAjmVWwx67NvPviE-CL2w.png</url>
            <title>Stories by Sayan Sinha on Medium</title>
            <link>https://medium.com/@americast?source=rss-6aae5c21a399------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 07:12:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@americast/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Constrained creativity]]></title>
            <link>https://medium.com/@americast/constrained-creativity-96dac4253a5e?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/96dac4253a5e</guid>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[aiagentsdevelopment]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 15:40:11 GMT</pubDate>
            <atom:updated>2026-10-13T15:40:11.843Z</atom:updated>
            <content:encoded><![CDATA[<p>TL;DR: Constraining an ops agent’s action space makes it explainable and cost-effective, without hurting accuracy.</p><p>AI agents hold promise to automate systems operations. However, it’s the engineers who stay accountable for every change, and they need explainability to trust the agent.</p><p>By and large, an ops agent needs to come up with pipelines that are:</p><p>• Effective: right answers, even on incidents it has not seen</p><p>• Efficient: keeps pace with alert volume, at a reasonable cost</p><p>• Explainable: an evidence trail an engineer can check</p><p>An LLM writing free-form code might reach the right answer, but its work is hard to check and its exploration and thinking keep burning tokens.</p><p>Our pitch: constrained creativity. Give the agent only as much freedom as the task needs, and let it be creative inside those limits. More room than a fixed playbook. Far less than arbitrary code.</p><p>But doesn’t this sound backwards? Shouldn’t an agent facing new cases get unlimited freedom? History has plenty of counterexamples. Jazz improvisers create inside fixed chord changes. Dr. Seuss wrote Green Eggs and Ham on a bet to use only 50 words. So much so that a 2017 psychology study found the same pattern and named it the Green Eggs and Ham hypothesis: constraints help creativity.</p><p>Recent agent systems already apply this idea implicitly:</p><p>• Jev (TypeSafe) and OpenAI’s Decisions API: the model returns a typed choice, score, or yes/no</p><p>• CaMeL (Google DeepMind): the agent writes restricted Python that a policy checker runs</p><p>• Grammar-constrained decoding: output must parse</p><p>On similar lines, we propose giving ops agents a domain-specific language (DSL) and letting them be creative inside it. Domain experts define the grammar and an initial set of building blocks for the task. For each incident, the LLM composes the blocks into a new program that follows the grammar. A verifier checks each program before it runs. Lego blocks instead of raw code.</p><p>The library of blocks can grow over time, following Occam’s razor: the agent reuses a known program first and composes a new one from existing blocks next. The agent writes a new block only when neither works, keeping the system expressive enough for its task. The grammar never loosens: new blocks use the same types, and every program still passes the verifier.</p><p>The results? Up to 12x cheaper root cause analysis without losing accuracy, and red-teaming agents that finish multistage attacks free-form LLMs could not.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRXES3DVAN7WlZ-Um2S-_g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96dac4253a5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Travis “Continuous” Integration]]></title>
            <link>https://medium.com/koss-engineering/travis-continuous-integration-7eae75dfcdba?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eae75dfcdba</guid>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 04:56:34 GMT</pubDate>
            <atom:updated>2019-09-18T09:54:47.930Z</atom:updated>
            <content:encoded><![CDATA[<p>There might be a need to update the contents of a website at certain intervals of time. I exploited Travis CI to serve my purpose for a website hosted on GitHub pages, automatically.<br> Continuous Integration is the practice of merging small patches to the shared mainline frequently. This practice is more common compared to merging in a massive change at the end of a development cycle as it is believed to prevent integration problems. But along with that, it becomes the responsibility of the developer to test every small change they make, which might make continuous integration intimidating. To address such issues the concept of build servers were introduced, which would perform the tests automatically as soon as a new change was proposed. This makes sure the changes introduced do not bring in new bugs. By and by, as it became common to host programs online, there was a need to have such build servers on the internet. Travis CI is one such service which provides distributed continuous integration service and is used to build and test programs hosted at GitHub. It is the most popular continuous integration service and provides support for both Linux and Mac environments.<br> Travis CI provides a lot of options regarding when to test code. It can be set up to check the code on any branch of a repository as soon as a commit is pushed, or automatically from time to time. I exploited this feature of Travis CI to update the contents of a website hosted using GitHub pages automatically.<br>In situations such as updating status, or updating some counter, or updating feeds, where one needs to update the website only after a certain amount of time, using this hack might be handy. Moreover, it helps to avoid the costs of hosting the stuff on a paid server for a task as simple as this. <br> I made use of the fact that a commit triggers Travis CI to execute tests. If the test script can be designed in a way that it does the necessary updates and pushes another commit just before it completes, Travis CI will be triggered again to conduct the tests, and this process goes on and on.</p><p><strong>Procedure</strong></p><p><em>.travis.yml </em>is the script which conducts the test, and its syntax is well explained in the <a href="https://docs.travis-ci.com/user/customizing-the-build">Travis CI docs</a>. We have a script <em>git_config.sh </em>which sets all the necessary settings in git. <em>deploy.sh</em> is our built script where the necessary update is carried out. Finally, <em>push.sh</em> is used to create a commit and push to GitHub.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b3c999f9b74b0dd5d3b1711235139e7/href">https://medium.com/media/1b3c999f9b74b0dd5d3b1711235139e7/href</a></iframe><p>Here, language is set to bash. One may feel free to choose any language as per requirement. First, we configure git branches and switch it to <em>master</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da1d3eaf989bff0eb67a874358eea599/href">https://medium.com/media/da1d3eaf989bff0eb67a874358eea599/href</a></iframe><p>One needs to generate a personal access token, referred to as the <em>OUATH_KEY</em> here, from the GitHub website. If you are logged in, you can create it here. This needs to be placed as environment variables in the Travis CI settings for that particular repository. The settings page would be available at https://travis-ci.org/&lt;GitHub handle&gt;/&lt;repository name&gt;/settings</p><p>We create a new remote in git with the <em>OUATH_KEY</em> in the URL so that we have permission to push to it. We fetch from it and checkout to the remote origin. The <em>deploy.sh</em> contains the scripts to update the contents (or whatever is desired). For testing purpose, one may merely make the script create a text file with randomly generated string to make sure there is always a diff, and we can successfully make a commit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87139b55672ac879a1b91e8095eb716b/href">https://medium.com/media/87139b55672ac879a1b91e8095eb716b/href</a></iframe><p>The next step is interesting as well. Travis CI does a shallow clone of a repository, which comprises only up to 50 previous commits. We unshallow it, for, if not done, one may not be able to force push. Force pushing is needed so that the repository does not get cluttered with commits. We delete the existing deployment branch (here known as “<em>gh-pages</em>”) and create a new one. We checkout to it from the <em>master</em> branch and make a commit on top of it. This makes sure that the deployment branch is just one commit ahead of the <em>master</em> and that any changes made to the <em>master</em> would get incorporated in the deployment branch at the next build.</p><p>In the next step, we configure git with username and email. It is recommended to use a fake email and username (or one with which no GitHub account exists) to avoid an explosion in the contribution chart. The commit is impressive as well. Other than the files to be deployed, we add a file <em>hist.txt</em> to the staging area. This is the file that contains a randomly generated string and is created everytime <em>deploy.sh</em> runs, as mentioned before. This makes sure that even if there’s no update of status, the commit occurs. It is crucial for the commit to occur. Otherwise, the Travis won’t be triggered again. Next, we force push the files.</p><p>Please note that this is to be used only in cases in which reliability is not an issue, as Travis CI often suffers network problems, and builds can fail. I have seen builds failing at least once in two months. Restarting the build generally fixes the issue. Nevertheless, Travis CI has a cron system which makes sure that even if a build fails, it’s restarted automatically once in the next 24 hours.</p><p>Example usage of this system can be seen in the MetaKGP <a href="https://naarad.metakgp.org/">Naarad</a> site, which is updated roughly every 30 minutes using this method. The repository is hosted <a href="https://github.com/americast/naarad-source">here</a>. <a href="https://travis-ci.org/americast/naarad-source">This</a> is the link to the corresponding Travis CI page.</p><p>Hope you found this post helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eae75dfcdba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/koss-engineering/travis-continuous-integration-7eae75dfcdba">Travis “Continuous” Integration</a> was originally published in <a href="https://medium.com/koss-engineering">KOSS Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Addressing issues with GPUArrays in Julia]]></title>
            <link>https://medium.com/@americast/addressing-issues-with-gpuarrays-in-julia-939b70419ba3?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/939b70419ba3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[julia]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 22:10:34 GMT</pubDate>
            <atom:updated>2018-07-10T22:10:34.773Z</atom:updated>
            <content:encoded><![CDATA[<p>GPU computing is extremely popular today and there is a need for easy creation of kernels. One challenge faced in GPU computing is the creation of separate kernels for OpenCL and CUDA. <a href="https://github.com/juliagpu/gpuarrays.jl/">GPUArrays</a>, a <a href="https://github.com/JuliaGPU">JuliaGPU</a> package, comes to a rescue. It enables one to write on kernel code which would work on both OpenCL and CUDA. GPUArrays is an easy to use Julia package which makes it convenient to create kernels without bothering about the device. Definitely, there are some issues with the package but they can be overcome by following some workarounds. Here I mention some issues which are prominent with GPUArrays :</p><ul><li><strong>Accessing register memory:</strong> GPUArrays does not provide any special function or macro to allocate memory in the register. Any local variable declared inside the kernel is supposed to be allocated in the register. Unfortunately, Julia allocates any mutable type only in the heap. Since GPUs provide only stack memory, it is not possible to have arrays in the register memory. This provides a major drawback over C, but there are workarounds. The idea is to use a tuple in place of an array. Whenever the tuple needs to be modified, a new tuple with updated data is created in its place. This gets the work done but might require some performance overhead. Probably, the best way to handle this is by creating tuples using the do statement, such as</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2543a19b90f528e94a55d5cb0b1cb807/href">https://medium.com/media/2543a19b90f528e94a55d5cb0b1cb807/href</a></iframe><ul><li><strong>Type inference issue:</strong> Julia faces type inference issue, mostly inside a closure. This is clearly highlighted by this issue <a href="https://github.com/JuliaLang/julia/issues/15276">https://github.com/JuliaLang/julia/issues/15276</a>. Type inference issues might not create a havoc in CPU based computations, but for the GPU it’s a pretty big deal as datatypes mean a lot to the GPU. Inside a closure, Julia fails to infer datatypes correctly and often promotes them to <em>Any</em> or some other supertype, which is a big no for the GPU, which requires datatypes to be specific. The use of the do statement involves a closure and type inference issues might be faced. In this case, a metaprogramming technique might be used. A function which converts all variables with an outside scope to local variables inside a closure can be used and this helps fix the type inference issue.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/381633114bec54b05ddf34f62714a937/href">https://medium.com/media/381633114bec54b05ddf34f62714a937/href</a></iframe><p>where WPT, acc, Asub, Bsub, TS, RTS, row, col, k are variables with an outer scope.</p><ul><li><strong>Using <em>@inbounds</em>:</strong> In GPU computing in Julia, it’s a must to use <em>@inbounds</em>. It serves two purposes. First, bounds checking involves some throw statements, and any kind of exception handling is not allowed on the GPU. Along with that, prevention of bounds checking helps make computations fast. Therefore, it becomes compulsory to avoid bounds checking. It is to be noted that <em>@inbounds</em> returns void, hence when used with a <em>do</em> statement, inside the closure a direct use of <em>@inbounds</em> would not help as the value computed will not be returned. In this case, a <em>@inbounds return</em> may be used.</li><li><strong><em>@LocalMemory</em> hates UInt32:</strong> Inside the kernel, one should always use UInt32 datatype in place of Int64. But it is to be noted that using UInt32 while describing the amount of shared memory to be allocated inside a kernel is not a recommended approach as it might lead to an error which states too many resources were demanded, even if the number of threads is kept below the limit for that specific hardware.</li><li><strong>Using print statements:</strong> Often, for debugging, one might have a desire to use print statements inside the kernel. Though the C library of OpenCL facilitates this with a simple <em>printf</em> statement, GPUArrays does not provide any direct method of doing so. The best way is thus to use another array where the values of variables to be debugged can be written and print statements can be used inside the launch code to view the values. Alternately, a less recommended way is to use <em>@cuprintf</em> which is a part of the CUDAnative package (which is used to write CUDA kernels in Julia). It is less recommended as it might disturb the parallelism and synchronisation procedures. Currently, it’s behaviour can be best described as undefined. I have noticed that <em>@cuprintf</em> works best if only one parameter is printed in a single statement. In case more than variable is passed and their values are demanded, it is difficult to explain exactly how this would work.</li></ul><p>Debugging techniques:</p><ul><li><strong>Using JLArrays:</strong> When there’s some issue with the kernel and it’s consistently giving an <em>LLVM IR</em> error, it is highly probable that there might be some bug in the kernel which is not GPU specific, i.e., it would create problems even if run on a CPU, such as syntax errors or bounds errors. In this case, the best way would be to pass a JLArray in place of a CuArray or ClArray to the kernel. JLArray is an array which runs on the CPU. Thus, we are able to mimic the kernel on the CPU. The errors produced are less cryptic and makes debugging pretty easy.</li></ul><p>Limitations of JLArrays:</p><p>— JLArray allows one to allocate heap memory inside the kernel.</p><p>— Type inference issues generally do not cause problems for JLArrays.</p><p>— Arrays accessed without <em>@inbounds</em> do not cause any issues.</p><p>— JLArrays allows one to access the same memory location from different threads, which is otherwise not allowed on the GPU.</p><ul><li><strong>Check for type inference issues: </strong>The best way to go about this is to use <em>@code_warntype</em> macro to find out what’s wrong. It lists sequence steps of the function calls as a metaprogram and clearly states which variable took which datatype. In case one finds something unexpected, one may use the steps mentioned above.</li><li><strong>Different threads should not mutate the same memory location:</strong> If the same memory location is accessed and mutated by different threads, the value assigned by one thread might not be available to another as long as the same kernel is involved, even if the second thread mutates at a later point in time. Thus, this practice should be avoided.</li><li><strong>Check for the presence of <em>@inbounds</em></strong>: <em>@inbounds</em> and <em>@inbounds return</em> should be placed at appropriate places.</li><li><strong>All external functions to the kernel are to be inline:</strong> Check if all the external functions which the kernel calls are inline. Along with that, for functions containing metaprogram, it is recommended to use <em>@generated</em>. In that case, the function itself does not have to dynamically determine the number of input arguments and separate functions would exist for all possibilities of the input.</li></ul><p>I hope this article would be beneficial to people involved in GPU computing. I encourage them to take up GPUArrays for their projects. If the above mentioned points are kept in mind while designing the kernels, I guess it using GPUArrays would be a pleasure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=939b70419ba3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks: Problems & Solutions]]></title>
            <link>https://medium.com/data-science/neural-networks-problems-solutions-fa86e2da3b22?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa86e2da3b22</guid>
            <category><![CDATA[artificial-neural-network]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 20:19:51 GMT</pubDate>
            <atom:updated>2017-07-29T08:05:20.649Z</atom:updated>
            <content:encoded><![CDATA[<p>Though the concept of artificial neural network has been in existence since the 1950s, it’s only recently that we have capable hardware to turn theory into practice. Neural networks are supposed to be able to mimic any continuous function. But many a times we are stuck with networks not performing up to the mark, or it takes a whole lot of time to get decent results. One should approach the problem statistically rather than going with gut feelings regarding the changes which should be brought about in the architecture of the network. One of the first steps should be proper preprocessing of data. Other than mean normalisation and scaling,<strong> Principal Component Analysis</strong> may be useful in speeding up training. If the dimension of the data is reduced to such an extent that a proper amount of variance is still retained, one can save on space without compromising much on the quality of the data. Also, neural networks can be trained faster when they are provided with less data.</p><p>Reduction in dimension can be achieved by decomposing the covariance matrix of the training data using singular value decomposition into three matrices. The first matrix is supposed to be contain eigenvectors. Furthermore, the set of vectors present in the matrix are orthonormal, hence they may be treated as basis vectors. We pick the first few vectors out of this matrix, the number being equal to the number of dimensions we wish to reduce the data into. Making a transformation of the original matrix (with original dimensions) with the matrix we obtain in the previous step, we get a new matrix, which is both reduced in dimension and linearly transformed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*pwzEKvHj7qBqHaPM7J5y4A.png" /><figcaption>The sum of the lengths of the blue lines is to be minimised (2D to 1D)</figcaption></figure><p>The above steps are mathematical in nature, but essentially we simply “projected” the data from the higher dimension to a lower dimension, similar to projecting points in a plane on a well-fitting line in a way that the distances a point has to “travel” is minimised.</p><p>An Octave implementation of the PCA would be :</p><pre>function [U, S] = pca(X)<br>  [m, n] = size(X);<br>  U = zeros(n);<br>  S = zeros(n);<br>  Sigma=(1/m)*(X&#39; * X);<br>  [U, S, V] =svd(Sigma);<br>end</pre><pre>function Z = projectData(X, U, K)<br>  Z = zeros(size(X, 1), K);<br>  U_reduce = U(:, 1:K);<br>  Z = X*U_reduce;<br>end</pre><pre>load (&#39;&lt;data&gt;&#39;);                     % Loads the dataset into<br>                                     % variable X<br>[X_norm, mu, sigma] = Normalise(X);  % Performs normalisation<br>[U, S] = pca(X_norm);                % Performs PCA<br>K = input(&quot;Enter reduced dimension&quot;);<br>Z = projectData(X_norm, U, K);</pre><p>One may use PCA for visualising the data by reducing it to 3D or 2D. But, a more recommended method would be to make use of <strong>t-distributed stochastic neighbour embedding</strong>, which is based on a probability distribution, unlike PCA. t-SNE tries to minimise the difference between the conditional probability in the higher and the reduced dimensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*u92Cpw35fcyWaeCd1FhZcQ.png" /><figcaption>Conditional probability in the higher dimension</figcaption></figure><p>The conditional probability is high for points close together (measured by their Euclidean distance) and is low for the once which are far apart. Points are grouped according to the obtained distribution. The variance is chosen such that points in dense areas are given a smaller variance compared to points in sparse areas.</p><p>Though it was proved by George Cybenko in 1989 that neural networks with even a single hidden layer can approximate any continuous function, it may be desired to introduce polynomial features of higher degree into the network, in order to obtain better predictions. One might consider increasing the number of hidden layers. In fact, the number of layers of a network is equal to the highest degree of a polynomial it should be able to represent. Though this could also be achieved by raising the number of neurons in the existing layers too, that would require far more neurons (and hence an increased computational time) compared to adding hidden layers to the network, for approximating a function with a similar amount of error. On the other hand, making neural nets “deep” results in unstable gradients. This can be divided into two parts, namely the <strong>vanishing</strong> and the <strong>exploding</strong> gradient problems.</p><p>The weights of a neural network are generally initialised with random values, having a mean 0 and standard deviation 1, placed roughly on a Gaussian distribution. This makes sure that most of the weights are between -1 and 1. The sigmoid function gives us a maximum derivative of 0.25 (when the input is zero). This, combined with the fact that the weights belong to a limited range helps makes sure that the absolute value of their product too is less than 0.25. The gradient of a perceptron comprises the product of many such terms, each being less than 0.25. The deeper we go into the layers, we’ll have more and more such terms, resulting in the vanishing gradient issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*X3hY9hLxsuRtn7rdv-THeg.jpeg" /><figcaption>Backpropagation of weights</figcaption></figure><p>Essentially, the gradient of a perceptron of an outer hidden layer (closer to the input layer) would be given by the sum of products of the gradients of the deeper layers and the weights assigned to each of the links between them. Hence, it is apparent that shallow layers would have very less gradient. This would result in their weights changing less during learning and becoming almost stagnant in due course of time. The first layers are supposed to carry most of the information, but we see it gets trained the least. Hence, the problem of vanishing gradient eventually leads to the death of the network.</p><p>There might be circumstances in which the weight might go beyond one while training. In that case, one might wonder how vanishing gradients could still create problems. Well, this might lead to the exploding gradient problem, in which the gradient in the earlier layers become huge. If the weights are large and the bias is such that it’s product with the derivative of the sigmoid of the activation function too keeps it on the higher side, this problem would occur. But, on the other hand, that’s a little difficult to achieve, for, increased weight may result in higher value for the input to the activation function, where the derivative of sigmoid would be pretty low. This also helps establish the fact that the vanishing gradient issue is difficult to prevent. In order to address this problem, we choose other activation functions, avoiding sigmoid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*dVoDR24VRWfn3l7alQLWMQ.png" /></figure><p>Though sigmoid is a popular choice as it squashes the input between zero and one, and also for its derivative can be written as a function of sigmoid itself, neural networks relying on it might suffer from unstable gradients. Moreover, the sigmoid outputs are not zero centred, they are all positive. This means, all the gradients would either be positive or negative depending on the gradient of units on the next layer.</p><p>The most recommended activation function one may use is <strong>Maxout</strong>. Maxout maintains two sets of parameters. The one which yields higher value to be presented as input to the activation function is used. Also, the weights may be varied according to certain input conditions. One such attempt leads to Leaky Rectified Linear Units. In this special case, the gradient remains 1 when the input is greater than 0, and it gets a small negative slope when it’s less than 0, proportional to the input.</p><p>Another trouble which is encountered in neural networks, especially when they are deep is <strong>internal covariate shift</strong>. The statistical distribution of the input keeps changing as training proceeds. This can cause a significant change in the domain and hence, reduce training efficiency. A solution to the problem is to perform normalisation for every mini batch. We compute the mean and variance for all such batches, instead of the entire data. The input is normalised before feeding it into almost every hidden layer. The process is commonly known as <strong>batch normalisation</strong>. Applying batch normalisation can assist in overcoming the issue of vanishing gradients as well.</p><p>Regularisation can be improved by implementing <strong>dropout</strong>. Often certain nodes in the network are randomly switched off, from some or all the layers of a neural network. Hence, in every iteration, we get a new network and the resulting network (obtained at the end of training) is a combination of all of them. This also helps in addressing the problem of overfitting.</p><p>Whatever tweaks are applied, one must always keep a track of the percentage of dead neurons in the network, and adjust the learning rate accordingly.</p><p>Certain diagnostics may be performed on the parameters to get better statistics. Plots on<strong> bias</strong> and <strong>variance</strong> are two important factors here. They can be determined by plotting curves with the output of the loss function (without regularisation) on the training and the cross validation data sets versus the number of training examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*jjp_6OHijUROG3Xs06mJWw.png" /><figcaption>(i) High bias (ii) High variance</figcaption></figure><p>In the figure above, the curve in red represents the cross validation data while the colour blue has been used to mark the training data set. The first figure is the one which would be roughly obtained when the architecture is suffering from high bias. It means, the architecture is poor, hence it gives pretty high errors even on the training data set. Addition of more features into the network (like adding more hidden layers, and hence introducing polynomial features) could be useful. If it is suffering from high variance, it means the trained parameters fits the training set well, but performs poorly when tested on “unseen” data (the training or the validation set). This could be because the model “over-fits” the training data. Getting more data could act as a fix. Reducing the number of hidden layers in the network might also be useful in this case. Playing with the regularisation parameter could help as well. Increasing its value could fix high variance whereas a decrease should assist in fixing high bias.</p><p>An Octave implementation of plotting diagnostic curves would be:</p><pre>function [error_train, error_val] = ...<br>    learningCurve(X, y, Xval, yval, lambda)<br><br>  m = size(X, 1);<br>  error_train = zeros(m, 1);<br>  error_val   = zeros(m, 1);<br><br>  for i = 1:m<br>    X_here = X(1:i,:);<br>    y_here = y(1:i);<br><br>    theta = train(X_here, y_here, lambda);<br>	    <br>    error_train(i) = LossFunction(X_here,y_here,theta,0);   <br>    error_val(i) = LossFunction(Xval,yval,theta,0);<br>   end;<br><br>end</pre><pre>lambda = input(&quot;Enter regularisation parameter&quot;);<br>[theta] = train(X_poly, y, lambda);</pre><pre>graphics_toolkit &quot;gnuplot&quot;;<br>figure(1);<br>[error_train, error_val] = ...                               <br>    learningCurve(X_poly, y, X_poly_val, yval, lambda);                       plot(1:m, error_train, 1:m, error_val);<br>xlabel(&#39;Number of training examples&#39;);                    ylabel(&#39;Error&#39;);<br>legend(&#39;Train&#39;, &#39;Cross Validation&#39;);</pre><p>Though it has been noticed that a huge number of training data could increase the performance of any network, getting a lot of data might be costly and time consuming. In case the network is suffering from high bias or vanishing gradients issue, more data would be of no use. Hence simple mathematics should be implemented as it would guide us which step we should descend towards.</p><p><strong>References:<br>* </strong><a href="https://www.coursera.org/learn/machine-learning">Machine Learning, Stanford University</a><br>* <a href="http://cs231n.stanford.edu/">Convolutional Neural Networks for Visual Recognition, Stanford University</a><br>* <a href="http://neuralnetworksanddeeplearning.com/">Michael A. Nielsen, “Neural Networks and Deep Learning”, Determination Press, 2015</a><br>* <a href="https://gab41.lab41.org/batch-normalization-what-the-hey-d480039a9e3b">Batch Normalization — What the hey?</a> (by <a href="https://gab41.lab41.org/@karl1980.lab41?source=post_header_lockup">Karl N.</a>)<br>* <a href="https://medium.com/@nishantnikhil/paper-summary-character-level-convolutional-networks-for-text-classification-6edf86e65106"><em>Paper summary</em> → Character-level Convolutional Networks for Text Classification</a> (by <a href="https://medium.com/@nishantnikhil?source=post_header_lockup">Nishant Nikhil</a>)<br><strong>Code repository:</strong> <a href="https://github.com/americast/ML_ANg">https://github.com/americast/ML_ANg</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa86e2da3b22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/neural-networks-problems-solutions-fa86e2da3b22">Neural Networks: Problems &amp; Solutions</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computer Vision: An Introduction to Perception]]></title>
            <link>https://medium.com/@americast/perception-41c2e241ef5f?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/41c2e241ef5f</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[perception]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Thu, 22 Jun 2017 11:13:02 GMT</pubDate>
            <atom:updated>2017-10-10T14:55:16.158Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZKVNfXFLOaEDJTgkxJJIw.png" /></figure><p>Photography is an art which I could never master. May be it was my half-hearted attempt or the lack of proper gadgets, the fact remained that photos I captured would not be upto the mark. I thought it was time I took it to a deeper level. I wanted to analyse vision from a mathematical point of view. As a part of a project work under <a href="http://swarm-iitkgp.github.io/">Swarm Robotics, IIT Kharagpur</a>, I kickstarted this summer (2017) by taking a course on <a href="https://www.coursera.org/learn/robotics-perception">Robotics Perception on Coursera</a>. I present a brief “lecture-note” of the same in this article.</p><p>Most of us are familiar with isometric view which we learned during our Engineering Drawing lectures. It’s a 3D view of an object in real world, with a fixed pair of perpendicular lines (the coordinate axes) being 120° apart. Isometric views carry a lot of information in themselves, hence are very important in architecture. On the flip side, a perspective projection is the one which mimics the human eye — the one obtained in photographs. A stark difference between the two lies in the fact that parallel lines remain parallel in isometric view, whereas in perspective view, they may meet at a point termed as the “vanishing point”. Various sets of parallel lines on a plane may meet at various vanishing points. Joining all of them we get a horizon, a line (on an image) which is specific to a plane (in the real 3D world).</p><p>In computer vision, we generally tend to work with homogeneous coordinates. We represent a point by a line and a line by a plane by adding a third coordinate i.e. we add an extra dimension. Considering ourselves to be at the origin, we imagine the image to be placed a unit distance (along the z axis) away from us. Accordingly, the horizontal becomes the x axis and inverse of the vertical becomes y. For a point on the image, we imagine a ray passing from the origin to the image plane and extending beyond. For a line, we simply imagine two more distinct lines, each passing through the origin and meeting the line on the image plane at two different points. These three lines make a plane. Formulas involving homogeneous coordinates are often simpler and more symmetric than their Cartesian counterparts.</p><p>A point in the 3D world is in respect to some coordinate frame which might not be the same as the camera frame. In order to bridge the gap, we use a matrix of transformation. We first write the 3D point in homogeneous coordinates by adding a ‘1’ to it. The matrix has two parts — relative rotation and translation, of the world coordinates with respect to the camera coordinates. I present an image below to illustrate the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*0xGeyMy4r-sVKPBitqlK7A.png" /></figure><p>Here the first one is the rotation matrix, and the second one is for translation. The x,y and z axes have been represented by Red, Green and Blue (RGB). The matrix is simply the relative position of the coordinate axes. For instance, the y axis of the camera is opposite the z axis of the world, hence (0,0,-1). Often the the translation matrix is augmented with the rotation matrix and a row is added below with (0,0,0,1) as it’s elements. This is done so that the matrix remains invertible and also because it brings in support for homogeneous coordinates. We further use another matrix containing intrinsic camera parameters which is pre-multiplied to get the points in 2D image coordinates. The overall picture looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*GZlP9ykxXjh8TR6dsI-OGw.png" /></figure><p>where fx and fy are focal lengths along x and y axes respectively. s is the scale factor as the camera may not be completely horizontal. px and py are the principal points i.e. where rays hit the centre of the image. K is known as the “calibration” matrix.</p><p>We assume images to be formed out of the pin hole camera model, something with which we are familiar with since childhood. The image formed is imagined to be at a a distance in front of the hole as the distance between the hole and the screen. An interesting visual effect worth discussing here is the dolly zoom. It occurs when we simultaneously move back the camera and zoom in (or vice versa) so that the size of the subject remains the same. As a result, the background which is out of focus, changes it’s size.</p><p>The equation of the horizon line can be derived from a set of vanishing points lying on the line. If we take into consideration homogeneous coordinates, we can say that the plane of the horizon remains parallel to the ground plane.</p><p>If we have three vanishing points, and a set of three mutually perpendicular axes connecting each of them, the distance between the origin and the ortho-centre of the triangle formed from the three points give us the focal length. This helps in finding camera parameters just from an image. We can also estimate heights of objects which are parallel in the real world by taking their relative heights. For instance, if we have the ends of objects (lying in the same plane) meeting at the same vanishing point, we can say they have the same length (assuming the image has been captured horizontally). What if this assumption is invalid? Moreover, how would we understand if the image is horizontal or not? A simple way is to see where the horizon lies. If it goes across the image from the centre, the assumption is valid. In case it doesn’t, we need the concept of cross-ratio to determine the distances. They can no longer be computed using simple ratio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*jPr826BVfnB-Jfj9QUXcaw.png" /></figure><p>Here, A, B, C and D can be considered to lie on the image plane and A’, B’, C’ and D’ in the ground plane (or vice versa). In case one of the points (say D) is a vanishing point, the corresponding point in the ground plane (D’) lies at infinity. Thus, by taking limits tending to infinity, the RHS reduces to A’C’/B’C’. Hence, even very limited amount of information can help us decipher a lot from an image if we have the knowledge of vanishing points, more importantly, without getting any intrinsic parameters of the camera involved.</p><p>A projective transformation is an invertible matrix of transformation which transforms an image viewed from a certain angle to an image as it would appear if viewed from another angle. For a set of points, we can simply post-multiply the coordinates with the matrix to get a set of new coordinates in the other plane. This matrix (known as the homography matrix) is obtained in a very interesting manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*nCK-kSfE8rEIKHQJdMMf-Q.png" /></figure><p>Here, we are shifting the coordinates in a such a way that from this view angle, the 2D image plane lies a unit distance in front of the new origin (along the z axis). When we take homogeneous coordinates into consideration, we take each point to be a ray emanating from the origin and moving towards the image plane. Since, the transformed original ray, and the new ray are supposed to be the same, or some linear combination (and hence parallel), we can say that their cross product should lead to a zero vector. This cross product can be written in a way such that the last row is a linear combination of the first two (the last matrix written at the left most corner of the image). Hence, ultimately, we are left with six unknowns. In case we avoid such complication and directly have a look at the matrix, it is composed of nine unknowns (3x3 homography matrix). Since, in homogeneous coordinates, the last one would be 1, we get one constraint and hence need eight other equations. Since every point gives us two equations, we need to know the transformed version of at least four points in the image to compute the homography matrix. While doing it the other way round, as usual, we need to take inverse of this matrix. The inverse is at times broken down into two matrices instead of three, by making the diagonal matrix in Single Value Decompostion, an identity matrix (discussed later), thus enforcing orthogonal contraints to it.</p><p>While moving from 3D to 2D, we have four more parameters (intrinsic camera features). Hence, we need to have at least six points in that case.</p><p>Detection invariance is a feature with which we can find correspondences between points of two images of the same object captured from a different scale and angle. This means, we should be able to map a point from one image onto the other such that they correspond to the same point in the 3D world, just by looking at the images. Descriptor invariance is a feature with which we can say that two images are pretty similar by studying a few sets of points and their neighbourhood. The most important issue faced regarding the two is maintaining a scale invariance i.e. detecting a pair of same points in both the images even when there is a drastic change in scale. We use a method known as SIFT (Scale Invariant Feature Transform) by David Lowe. Scale space is a notion can be used in images too. The main idea of a scale-space representation is to generate a one-parameter family of derived signals in which the fine-scale information is successively suppressed. This is obtained in images by administering a blur in the image. If we look at the just one pixel across all series of blurred images, we find that it’s intensity follows a curve similar to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*UMJg_aBKMEfoeHyoAlApCw.png" /></figure><p>For instance the Laplacian of Gaussian (LoG), the scalar double partial derivative of the Gaussian, is generally administered on an image before finding edges. But, using it directly makes it fade out, hence, we use a scale-normalised approach. We make sure we just have σ square in the denominator, just as in Gaussian. We compare the absolute values of the maxima (intrinsic scale) of the curve for various σ and choose the one which gets the highest value. The effects are drastic and hence leads to much better results in application (like edge detection, where we subtract the original image from the normalised one, and the absolute value of the result gives us prominent edges). An interesting property of LoG is that it can be approximately obtained by subtracting a Gaussian from another having different σ.</p><p>Singular Value Decomposition is factorisation of a matrix (A) into three parts MDN where A=MDN. Here M and N are such that a dot product of any column with itself leads to a zero vector. This means M.transpose(M)=I. D is a diagonal matrix with continuously decreasing values starting from the first element such that the last few elements are always zero. What’s interesting here is that if we take just the first few (say n) columns from the first matrix, n elements from the second and n rows from the third, we can extract certain features of the image. Here are a few examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*eBLaXtSQpw_GcE6MSsqzOg.png" /></figure><p>We often use the “Least Square Fitting” method to obtain a straight line from scattered points. But it gives us results far from optimum when we have noise in the data. Hence, we use an alternate way, known as RANSAC (Random Sample Consensus), Here we choose two random points and draw a straight line through it. We count the number of points which would line if we would draw imaginary lines parallel to one another separated by a distance ±ε. The one giving maximum number of points is taken to be the best fitting straight line.</p><p>In order to compute the rotation between two sets of coordinate systems, three points are enough. We take the cross product between two of the vectors and again a cross product with one of them gives us an orthogonal vector in case the original two vectors were not so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZdhUJE5i68UnLbzmB1Cpg.png" /></figure><p>Another question which arises is that rotation should be taken about which point. The answer is about the centroid. So, we try to minimise the square of A-RB, (where R is the rotation matrix). Here A and B are matrices containing the distance of each point from their respective centroids.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*T30Aa-rmCZqc9vE3Gih4bw.png" /></figure><p>Hence, Z is a diagonal matrix whose upper bound is given by identity, as the matrix is orthogonal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*ueAXVdlmy2Gfm8quoSST2w.png" /></figure><p>Now, we’ll have a look how to determine the position of the camera if we have knowledge of the location of certain points in the scene. If we know two 2D points and the angle between them, the camera could lie anywhere in this circle. If we are thinking in 3D, the camera could lie anywhere in a</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*UVFAYCPjVUl2dRdeuZ0Ugg.png" /></figure><p>toroid. If we add another point, we get a toroid for every two points. Hence, we can safely conclude the presence of the camera at the intersection of the three toroids. Breaking it down into simple geometry, we can make use of the cosine rule so that the unknown distances can be recovered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*Y_s0BLcxR8EEHnm6fwqGWA.png" /></figure><p>The derivation is pretty straight forward. We take d2=u d1 and d3=v d1. Applying cosine rule,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*dhMqREKeJ8DDGXq_dXxmtQ.png" /></figure><p>Hence,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*5JYAfnNhI4vCljBfsK2Axg.png" /></figure><p>Solving the first equation for the square of u and inserting it in the second, we solve for u and place it back in the first. In this way, we end up getting a biquadratic equation in v. The second equation generated was a quadratic in u, so for every u we have four solutions of v. Thus, we get eight results.</p><p>Stereoscopic vision gives two images (A and B) of the same scene, from different positions. Let’s assume we are able to see camera A from image B and camera B from image A. The respective cameras are known as epipoles. Every point in the image, when connected to the other camera forms a line in 3D which are called the epipolar lines. In order to find out the relative rotation and translation between the cameras, we need to have eight corresponding points in both the images. Why? Let’s assume camera A to be at the centre of the universe. So, it obtains a 3D (world) to 2D (image) transformation with k [I O] where k is the calibration matrix, I the identity matrix and O the null matrix. Here I is the rotation matrix and O, the translation. Accordingly, for camera B, it’s k[R t]. Here t is the line joining camera A and B, in camera B’s coordinate frame. We obtain three lines in camera B reference frame: t, which is the line of translation, X2 which is any ray from camera B to the image plane and going beyond. Let it meet the 3D object at point X1, so we have another ray, which is X2-t, which is Rx1 in camera B reference frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*79GhRgZs_lETtlvQNF6ivQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*zuDCeN4nJQEsAgrFaCxDgg.png" /></figure><p>Taking appropriate vector products and then a scalar product gives us zero. On expanding the matrix on the RHS, we are able to represent it with the help of an essential matrix by taking the transpose of (RX1) followed by the transpose of the entire expression. And since we have shown before that it’s a skew symmetric matrix, a negative sign gets attached to it. Now, if we change the point X2 in the image, we get different sets of planes. The planes cuts camera B image plane forming various lines which converge to the epipole, and these lines are known as the epipolar lines. The point X1 in camera A image plane will just be a scaling factor. Let’s say, pX1. The epipolar line on camera B image plane is EX1 and transpose of X2 multiplied by E for camera A. Hence the epipole for camera A is represented as Ee1=O where e1 is the epipole. For camera B, it’s transpose of e2 multiplied by E=O.</p><p>By and large, if a point is at X1 (3D) from the point of view of camera A and X2 from camera B, their relationship is expressed by the bilinear equation transpose of X2 E X1 = O. If the camera calibration matrix is K, the images obtained in camera A and B are given by KX2 and KX1 respectively. Replacing X2 by K inverse of x2 and X1 by K inverse of x1, we get that the transpose of x2 F x1 = O, where F is K inverse transpose E K inverse. The matrix F is known as the Fundamental Matrix. Just like E, the epipole times F equals O, hence it’s a second rank 3x3 matrix. Why? Because, any point represented in homogeneous coordinates have 1 as the z-coordinate. Hence, it means that the last row is a linear combination of the first two. Also, since there are total 3 dimensions in the points, the matrix must be 3x3. It has a total of nine elements, but there’s a scaling factor involved, for we are taking the z-coordinate to be 1. Hence, we are left with 8 unknowns. Thus,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*J-EKDz5rw-o0suvQV4kMkQ.png" /></figure><p>Hence, it gets reduced to a least square problem of AX=O. Thus, we need at least eight point correspondences. We normalise the last element to be 1 and accordingly bring the points back to the image plane.</p><p>In order to compute the rotation and translation, between two images, we need to decompose E as we know it is t x R. tx is written in the form of U A U transpose. Next, we break U into three parts, with the last one being the</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*XyLptH0NA7ElW16vSMo4Ug.png" /></figure><p>translation vector. We can further perform an SVD of R and equate it to U Y and the transpose of V. U U transpose gives us identity. So, by and large, we take SVD of E, breaking it into U, D and the transpose of V. The translation vector is either U or -U. Our rotation matrix is a multiplication of U and an unknown y, which can take two values, and V transpose. The determinant of the rotation matrix, as usual, should be 1. Thus, we have four possible configurations of rotation and translation for two images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*7hie0FeYGi_-eMXQG2Q2CQ.png" /></figure><p>Hence, we are able to determine the rotation and translation between the two images simply from the images captured.</p><p>I hope the lecture note presented above makes it easier for one to develop interest in computer vision. In order to churn out something practical from the knowledge gained above, I plan to work this semester on stereo-vision, and would definitely make a post on the outcome !</p><p><strong>Course credits:<br></strong><a href="https://www.coursera.org/instructor/daniilidis"><strong>Kostas Daniilidis</strong></a><strong>, </strong>Professor, Computer and Information Science<strong><br></strong><a href="https://www.coursera.org/instructor/shi"><strong>Jianbo Shi</strong></a><strong>, </strong>Professor, Computer and Information Science</p><p>School of Engineering and Applied Science<strong><br>University of Pennsylvania<br>Coursera.</strong></p><p><a href="https://www.coursera.org/learn/robotics-perception"><strong>https://www.coursera.org/learn/robotics-perception</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41c2e241ef5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance analysis: Julia, Python & C]]></title>
            <link>https://medium.com/hackernoon/performance-analysis-julia-python-c-dd09f03282a3?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd09f03282a3</guid>
            <category><![CDATA[performance-testing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[julia]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 18:49:42 GMT</pubDate>
            <atom:updated>2017-03-28T18:47:18.041Z</atom:updated>
            <content:encoded><![CDATA[<p>After my introduction to the world of open source, I had to work with various programming languages, based on the requirements of the project I was working on. I had worked on Python, Ruby, Java and C++. All Python programmers would agree that learning how to code (without going into internal details) in Python is pretty simple. A little practice and you can write a lot of powerful codes in just a few lines and certain big computations (for which even there’s no data-type available in C) can be achieved. It’s pretty similar for Ruby too, just that it doesn’t bother the programmers much about incorrect indentation. But, when it comes to performance, the C language stands way ahead of it’s interpreter-based counterparts.</p><p>Recently, I came across a new programming language — Julia. Well, it’s still in it’s late infancy but what interested me the most was that it promised an easy syntax, (like in Python) along with powerful performance (close to C), and it was interpreter-based too. I thought, “exactly, this is what we are looking for!” So, I decided to test it out on my own machine.</p><p>After glancing through the syntaxes of various commonly used commands in Julia, I coded out <strong>merge sort</strong>. The reason for choosing it was that it has a time complexity of n log n (base 2) for all cases. Hence, it would give reliable results on randomly generated numbers. I quickly programmed merge sort in Python and C too. I wrote another small piece of code in Julia (since I had started loving it!) to generate random integers. Using a shell script, I called all of them to compute the time required by each of the programs (C, Python and Julia) for number of integers from 10 to 1,00,00,000 (10⁷). The programs did not have I/O. The outcome was interesting. I present a pie chart below to illustrate the results.</p><p>The <a href="https://github.com/americast/Performance_analysis">program</a> was run on a system with 2.30 GHz 64-bit processor, 1.8 GiB memory, Linux 4.4.0, GCC : 4.0 (20160609), Python 2.7.12 (2016–06–25) and Julia 0.4.5 (2016–03–18 00:58 UTC).</p><p>10 (10¹):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrJ6hpUu8tnCe09fzXSpiw.jpeg" /></figure><p>100 (10²):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EJAqLaq5Jc_5Jf0F2P1gvQ.jpeg" /></figure><p>1,000 (10³):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HkGBMMHqa6FjJ5Jk7oieAQ.jpeg" /></figure><p>10,000 (10⁴):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XBEbPVOo-Qha2R5c_bvNA.jpeg" /></figure><p>1,00,000 (10⁵):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hh9qXw2FiPossRtUIjjyKA.jpeg" /></figure><p>10,00,000 (10⁶):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYiajTLRIktHGK18eb_2vg.jpeg" /></figure><p>1,00,00,000 (10⁷):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZDQZFVG6SQ4oiDb3pVLVQ.jpeg" /></figure><p>From 10⁵ onwards, Julia proves to be faster than Python as it keeps reaching the speed of C. From 10⁶ onwards, where C language fails with a segmentation fault, Julia puts up a pretty impressive performance, keeping it’s dominance over Python, in terms of speed, by a huge margin.</p><p>Digging under the hood, I noticed there is a difference in the amount of memory being allocated while appending to a linear data structure in Python and Julia. Python follows a factor of 1.125 plus a constant number, 6 (<a href="https://github.com/python/cpython/blob/202fda55c2dffe27125703225e5af92254602dc6/Objects/listobject.c#L32">click here</a> for reference).</p><p>It follows the pattern 8, 16, 25, 35, 46, 58, 72, 88, …</p><p>But Julia follows a factor of 2 (<a href="https://github.com/JuliaLang/julia/blob/f74cb71f5aa14835069d495db4380eefad5662a2/src/array.c#L737">click here</a> for reference). Hence, when it comes to large data, Julia outperforms Python by a huge margin.</p><p>In this article, we only went into the aspects of memory reallocation, while there are several other factors which make Julia more awesome and faster when compared to Python. I will discuss more about them in my following posts.</p><p>Repository of the code for merge sort: <a href="https://github.com/americast/Performance_analysis">https://github.com/americast/Performance_analysis</a></p><p>Reference to memory reallocation in Julia: <a href="https://github.com/JuliaLang/julia/blob/f74cb71f5aa14835069d495db4380eefad5662a2/src/array.c#L737">https://github.com/JuliaLang/julia/blob/f74cb71f5aa14835069d495db4380eefad5662a2/src/array.c#L737</a></p><p>Reference to memory reallocation in Python: <a href="https://github.com/python/cpython/blob/202fda55c2dffe27125703225e5af92254602dc6/Objects/listobject.c#L32">https://github.com/python/cpython/blob/202fda55c2dffe27125703225e5af92254602dc6/Objects/listobject.c#L32</a></p><p>Pie chart credits: <a href="http://meta-chart.com/">www.meta-chart.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd09f03282a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/performance-analysis-julia-python-c-dd09f03282a3">Performance analysis: Julia, Python &amp; C</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kharagpur Winter of Code]]></title>
            <link>https://medium.com/kharagpur-open-source-society/kharagpur-winter-of-code-c4eeb4af71f1?source=rss-6aae5c21a399------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4eeb4af71f1</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Sayan Sinha]]></dc:creator>
            <pubDate>Wed, 22 Feb 2017 08:59:40 GMT</pubDate>
            <atom:updated>2017-11-12T22:03:02.469Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Website : </em><a href="https://kwoc.kossiitkgp.in/"><em>https://kwoc.kossiitkgp.in</em></a></p><p>The world of open-source had enchanted me right after I had installed Linux in middle school. I was amazed to see all my daily needs of a computer being satisfied by free and open source software. But, I was just a mere user. I was pretty clueless as to how one could obtain, share and collaborate on the source code of an application.</p><p>I had a desire in me to explore the world of coding after coming to IIT. I wanted to see myself a developer, not just a user. I wished to get my hands dirty by altering open source codes. I contacted my mentor Kaustubh Hiware (<a href="https://github.com/kaustubhhiware">@kaustubhhiware</a>) for further information. He told me to commence by learning Git. I also sent a mail to Kharagpur Open Source Society (KOSS) regarding the same. Just as I ​​started with Git from <a href="https://www.codecademy.com/learn/learn-git">Codecademy</a> and <a href="https://youtu.be/cEGIFZDyszA?list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx">YouTube</a>, my mentor informed me about Kharagpur Winter of Code. I finally had something to guide me in this new venture. Also, I was glad I knew what to do in order to make the winter a little constructive. I started off by attending a workshop on Git, organised by KOSS, which helped refresh my memory.</p><p><a href="http://kwoc.kossiitkgp.in/">Kharagpur Winter of Code</a> (KWoC) is one month long program to introduce newbies to the world of open source. Anyone could register as a student, and a mentor as well. The students had to work on source codes which were hosted on <a href="http://github.com/">Github</a>, a web-based version control and repository hosting service. We were to code on some of the listed issues or we could create issues on our own. We had to fork it, edit the program, and send a ‘Pull Request’, which is a request for merging the work with it’s original version. I had used Git as the local client for version control on my system.</p><p>After my NSS Camp, I made list of projects that I would be working on. I wanted to try some easy stuff first. I chose <a href="https://github.com/metakgp/naarad-source"><strong>naarad-source</strong></a>. I was interested in <a href="http://naarad.metakgp.org/">Naarad</a> not only because of the fact that the issue listed seemed easy but also because I was an active user of Naarad. It is a news aggregator for collecting all news related to KGP. Naarad subscribes to news feed from important pages related to IIT Kharagpur and serves them at <a href="http://naarad.metakgp.org/">naarad.metakgp.org</a>. Naarad is really helpful for people like me who chose not to create a Facebook account. I placed a “last updated” time stamp at the top-right corner. It was heartening to see the response of the students at <a href="https://github.com/metakgp/">@metakgp</a>. My <a href="https://github.com/metakgp/naarad-source/pull/62">pull request</a> was accepted and indirectly, it gave me an incentive.</p><p>Next, I wanted to get a feel of android-development. I created a splash screen for an application by <a href="https://github.com/mayank-kgp/">@mayank-kg</a>p named <a href="https://github.com/mayank-kgp/VoiceCalculator"><strong>VoiceCalculator</strong></a> (which was pretty much in the “Hello, world!” stage). My <a href="https://github.com/mayank-kgp/VoiceCalculator/pull/8">pull request</a> was accepted after a few additional commits.</p><p>Next on the list was <a href="https://github.com/athityakumar/ruby-notificator"><strong>ruby-notificator</strong></a> by <a href="https://github.com/athityakumar/">@athityakumar</a>. It is a tool that would be able to read through one’s social media accounts and notify via emails. Two things encouraged me to take it up.​​ First, it was in Ruby, so it gave me a scope to learn a new language. Second,​ it too was in its infancy. So, I could mess up with it at my will. I started preparing for Ruby from <a href="https://www.codecademy.com/learn/ruby">Codecademy</a> and after a couple of days of practice, I began working on the project. I did a whole lot of work on it and created three <a href="https://github.com/athityakumar/ruby-notificator/pulls?q=is%3Apr+is%3Aclosed">pull requests</a> with huge amount of editing, out of which one <a href="https://github.com/athityakumar/ruby-notificator/pull/10">pull request</a> is yet to be merged. My mentor supported me throughout and provided valuable suggestions on making the code more memory efficient. Ruby-notificator is yet to be deployed.</p><p>At the end of the month, I was glad to see myself at the second position ​of the leader-board, with 20 commits. My net contributions:</p><p><a href="https://github.com/athityakumar/ruby-notificator/">ruby-notificator</a>: +1,137 -608 (in Ruby)​</p><p><a href="https://github.com/mayank-kgp/VoiceCalculator">VoiceCalculator</a>: +77 -1​ (in Java and XML)​</p><p><a href="https://github.com/metakgp/naarad-source">naarad-source</a>: +19 -2​ (in Python and HTML)​</p><p><strong>Overall: +1,233 -611</strong></p><p>KWoC was a lot more than experience and learning. Now, that I had worked on the repositories and had interacted with their makers, I became a permanent member of the projects. The mentors of some of the projects, along with me, have decided to work on certain long term goals of the programs, and I am still working with them.</p><p>On the 16th of January, 2017 I was gifted ​an official Mozilla t-shirt by KOSS for being the top contributor from IIT Kharagpur. I was also allowed a direct entry into their team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*CgGATEp3sK2c8v6YdO-ezQ.jpeg" /></figure><p>I would like to express my sincere gratitude to all the members of KOSS for taking this great initiative to introduce newcomers like me to the world of open-source. I would also like to thank my mentors for guiding me wherever required. I thank my parents for refreshing my enthusiasm throughout. Finally, I thank God, without whose desire these projects would not have been successful.</p><p>My Github handle: <a href="http://github.com/americast">@americast</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4eeb4af71f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kharagpur-open-source-society/kharagpur-winter-of-code-c4eeb4af71f1">Kharagpur Winter of Code</a> was originally published in <a href="https://medium.com/kharagpur-open-source-society">Kharagpur Open Source Society</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>