Responsive Ad Area

Month: February 2019

Gradient Descent cost function explosion

I am writing this code for linear regression and trying Gradient Descent to minimize the RSS. The cost function seems to explode to infinity within 12 iterations. I know this is not supposed to happen. Maybe, I have used the wrong gradient function for RSS (can be seen in the function “grad()”)? NumberObservations=100 minVal=1 maxVal=20 X = np.random.uniform(minVal,maxVal,(NumberObservations,1)) e = np.random.normal(0, 1, (NumberObservations,1)) Y= 10 + 5*X + e B = np.array([[0], [0]]) sum_y = sum(Y) sum_x = sum(X) sum_xy = sum(np.multiply(X, Y)) sum_x2 = sum(X*X) alpha = 0.00001 iterations = 15 def cost_fun(X, Y, B): b0 = B[0] b1 = B[1] s = (Y - (b0 + (b1*X)))**2 rss = sum(s) return rss def grad(X, Y, B): print("B = " + str(B)) b0 = B[0] b1 = B[1] g0 = -2*(Y - b0 - (b1*X)) g1 ...

JavaScript with show and hide using toggle or IF statements on Click

I am just struggling with this problem – for days now. Perhaps I over-complicated a simple piece of code.. but anyway I need to show some divs when a button is clicked, the first set of code would only trigger on the second click (because I used VAR.style.display) so I tried toggle but now it isn’t working at all… Please enlighten me what am I doing wrong? In this version of code I had the display: none; set on the 2 service menus (servicesMORE and servicesMOREE), and was just trying to change it when the button (serviceclick) is clicked. //serviceclick button opens menus $(".serviceclick").click(function(){ var service = document.getElementById("servicesMORE"); var serviceclick = document.getElementById("scroll_to_explore2"); //more than 768 and services hidden if(servic...

SQLITE 3 Not writing to table

I am trying to store an array of objects like this. "id": "EExKKTC8IuL", "date": "2019-02-18T14:57:52.997Z", "timestamp": "1550500384", "title": "Financial Giant SBI Aims to Boost Ripple and Push XRP Ahead of Bitcoin in Crypto Market CapFinancial Giant SBI Aims to Boost Ripple and Push XRP Ahead of Bitcoin in Crypto Market Cap", "score": 6, "comparative": 0.18181818181818182 Into a better-sqlitev3 table. I am usually able to do it with simple id KEY auto increment. But I am trying to keep the ID’s of the articles in the db so they dont duplicate. Here is the code. try { const table = "coinna" const dbFile = "scraped" const dataDir = "./data/" const dbExt = ".db" const dbConn = db(`${dataDir}${dbFile}${dbExt}`); dbConn.prepare("PRAGMA journal_mode = WAL").run(); dbConn .prepare( `CREA...

Activate default tabs based on condition

I have the following code a page that holds 3 tabs as follow: <div id="tab-container"> <button class="tablink" onclick="openPage('Wall', this, '#F06078')" id="defaultOpen">Wall</button> <button class="tablink" onclick="openPage('Profile', this, '#F06078')">Profile</button> <button class="tablink" onclick="openPage('Gallery', this, '#F06078')">Gallery</button> The idea is to make whatever tab that’s called on from a controller the default and land on it. I try passing $data to the page but it’s telling me it’s undefined. I also think maybe storing the info in a session and calling it on the page where the tabs are, but I’m not that flexible yet with the coding. function index ($page='wall') { $data['defaultOpen'] = 'wall'; $d...

Y_axis break in barplot 2

I am trying to break the y_axis in barplot2 because some values are very high. I tried using gap.barplot but it seems like it doesnot work fro barplot2. Please inform the way to break Y-axis values in barplot2. gap.barplot2(PO4PsR, beside=T,width= c(0.1,0.1,0.1), col = c(“black”, “grey”),las = 1, xlab = “Site code “, #main = “Stream”, names.arg = c( “R01”, “R03”, “R04”, “R10”, “R12”, “R14”, “R15”, “R16″), #cex.lab=0.9, cex.axis=0.9, gap = c(50, 200), gap.axis=”y”,ylim = c(0, 250), #ytics = c(seq(0, 50, by = 10), seq(200, 250, by = 10))) Y_axis break in barplot 2 Y_axis break in barplot 2 test {$excerpt:n}

Microsoft Power BI: Line chart last 13 weeks data for 3 years

I need to show line chart visual for last 13 years data for 2017,2018 and 2018. Can anyone tell me how I can achieve this? I have a table called Profit columns : Profit, WeekEndingDate, Year I tried to create last 13 weeks measure but only showed 7 weeks as we are only 7 weeks in 2019 and also only showed data for 2018 and 2019. I need to display each year individually with 13 weeks data. Microsoft Power BI: Line chart last 13 weeks data for 3 years Microsoft Power BI: Line chart last 13 weeks data for 3 years test {$excerpt:n}

AJAX request with poor performance FILE UPLOAD

I want to make my ajax file upload faster. I’m new using AJAX, and my question is, how can i optimize my code? It’s a from submit with 8 inputs and 1 file upload: Image of the form File upload takes too long, and I want to improve it. I have 3 AJAX requests; 1 for the vars on the form, another for the file and one repetitive for the inputs if the user leaves the upload empty. Here is my code for form submission & file upload: $("#enviar").click(function(event) { var formData = new FormData(this); var nome = $("#nome").val(); var apelido = $("#apelido").val(); var email = $("#email").val(); var nome_do_negocio = $("#nome_do_negocio").val(); var website = $("#website").val(); var cidade = $("#cidade").val(); var descricao = $("#descricao").val(); var gasto = $("#gasto").val()...

Process from Json file

I have a data file like this: `{ ‘day’:1, ‘month’:2, ‘hour’:2, ‘minute’:3, ‘second’:45 } { ‘id’:1, ‘offset’:0, ‘timeout’:5, ‘status’:0, ‘accuracy’:20, ‘name’:’Daisy’, ‘Pos’:’L’ } { ‘mode’:1, ‘dim’:0, ‘timestamp’:12 ‘virtual’:’yes’ ‘accuracy’:15 ‘rep’:0 ‘spare’:1 } ` I want the first entity only so i have written code like this: lst=[] with open('test.txt','r')as file: for line in file: if "id" in line: lst=lst[:-7] # if "timestamp" in line: # lst = lst[3:-5] else: lst.append(line) with open('final1.txt','w')as f: for line in lst: ...

Why does std::ostream not compile when used in ternary operator?

#include <iostream> using namespace std; int main() { std::ostream o(nullptr); true ? std::ostream(nullptr) : std::ostream(nullptr); // A true ? std::ostream(nullptr) : o; //B return 0; } I was wondering why A compiles fine while B fails with error: prog.cpp: In function ‘int main()’: prog.cpp:7:33: error: ‘std::basic_ostream<_CharT, _Traits>::basic_ostream(const std::basic_ostream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is protected within this context true ? o : std::ostream(nullptr); ^ So I found this site: https://docs.microsoft.com/en-us/cpp/cpp/conditional-operator-q?view=vs-2017 which says that when ternary operator has arguments (by “arguments” I mean the ones to the left and right of :) then it can cause co...

IOS pagehide not triggered. Cannot detecting page unload

I call this function when my page is loaded: function setBeacon() { if (!navigator.sendBeacon) { alert("No navigator beacon available. This is a critical bug which must be fixed."); } else { if ('beforeunload' in window) { $(window).on('beforeunload', function() { generateFormSendBeacon(); return undefined; }); } else if ('onpagehide' in window) { alert("on page hide"); window.addEventListener("pagehide", function() { generateFormSendBeacon(); return undefined; }); } else { alert("Neither beforeunload or onpagehide events are available. Please report this to John, with details about your browser."); } } } This works perfectly on desktop. I am using navigator.sendBeacon in the generateFormSendBeacon() function. It sends it correctly (I have a breakpoint in my server receiving this). On mobi...

How to alter a GTK+ label from an external function?

I have the following function in gui.c void gui(void *arg){ GtkWidget *window; GtkWidget *label; GtkWidget *layout; GtkWidget *image; //gtk_init(&argc, &argv); gtk_init(NULL, NULL); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 1024, 600); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); layout = gtk_layout_new(NULL, NULL); gtk_container_add(GTK_CONTAINER (window), layout); gtk_widget_show(layout); image = gtk_image_new_from_file("background.png"); gtk_layout_put(GTK_LAYOUT(layout), image, 0, 0); label = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(label), "<big>Big text</big>"); gtk_layout_put(GTK_LAYOUT(layout), label, 0, 0); g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main...

How do I access the array of json object inside jsonobject

How to access the array of json objects inside jsonobject. Here is the sample JSON. I am trying to access the values field in grop key and want to modify the values field. eg say set 2344 to 1111. Is there anyway using JSONnode or JSONObject library? Kindly suggest a java code that uses JSON lib instead of Gson. { "source": "avsg", "isDeleted": false, "attributes": { "name": [ { "values": [ "chi" ], } ], "category": [ { "values": [ "2ea09354-9816-4712-8f98-f803259b8d6c" ]} ], "xyz": [ { "values": [ "err" ], "lang": "english"} ], "grop": [ { "values": [ "2344"],"lang": "English"},{"values":["3333"],"lang":"French"} ] } } How do I access the array of json object inside jsonobject How do I access the array of json object inside jsonobject test {$excerpt:n}

  • 1
  • 2
  • 4
Skip to toolbar