Monday, July 24, 2017

getting jquery-ui to work with require and other functions

sm-other-demo.html
---------------------------------------------------------

<!-- Based off of draggable.html accompanying chapter12:
                <p>JavaScript &amp; jQuery: The Missing Manual, 3rd Edition, by <a href="http://sawmac.com/">David McFarland</a>. Published by <a href="http://oreilly.com/">O'Reilly Media, Inc</a>.</p>
-->

<!DOCTYPE html>
<html>
  <head>
     <link rel = "stylesheet" type="text/css" href="style.css">     
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width" orientation="portrait">
     <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
<!--     <link rel="stylesheet" href="http://localhost/test/sites/all/modules/jquery_update/replace/ui/themes/base/jquery-ui.css"> -->
     <link rel="stylesheet" href="./index-adid-strip-button.css">
           <script src="../../external/requirejs/require.js"></script>
        <script src="../bootstrap.js" data-modules="effect">
require(['isthebest'], function(isthebest) {

$( function() {
    var dialog, form,
      name = $( "#name" );

    function addUser() {

   //   var siteDomain = "http://localhost:8080/marmotta/sparql?query=";
      
//    $( "#users" ).append( name.val() );  
// I only want to append if name.val() ) resolves... (so I need to do an xmlhttp request...)
    $("#duck").append( d3sketch(name.val()) );

   //   $( "#users" ).append( siteDomain + encodeURIComponent(name.val()) );
        dialog.dialog( "close" );
    }
 
    dialog = $( "#dialog-form" ).dialog({
      autoOpen: false,
      height: 220,
      width: 285,
      modal: true,
      buttons: {
        "Execute": addUser,
        Cancel: function() {
          dialog.dialog( "close" );
        }
      },
      close: function() {
        form[ 0 ].reset();
      }
    });
 
    form = dialog.find( "form" ).on( "submit", function( event ) {
      event.preventDefault();
      addUser();
    });
 
    $( "#create-user" ).button().on( "click", function() {
      dialog.dialog( "open" );
    });
 
    $("#loadfileldpbutton").button().on("click", function() {
      //  alert("howdy");
          var $field = $('#textfield');
          var fieldVal = $field.val();
          alert(fieldVal);

          if(fieldVal) {
          
             // erase the present contents of the duck container
             var container = document.getElementById('duck');
             container.innerHTMl = '';
             // add new content to the duck container
//              $('#duck').append(fieldVal);
              $('#duck').append(isthebest(fieldVal));
//              $('#duck').append(d3sketch(fieldVal));  
          // $('#tasklist').replaceWith(d3sketch(fieldVal));
           $field.val('');
           $field.focus();
          }
    });

/*
    function isthebest(value) {
        return value+" is the best!";
    }
*/
/*
     $( "#loadfileldpbutton" ).button().on( "click", function() {
         var $field = $('#textfield');
         var fieldVal = $field.val();
         if(fieldVal) {
           // erase the present contents of the duck container
           var container = document.getElementById('duck');
           container.innerHTML = '';
           // add new content to the duck container via the tasklist id
           $('#tasklist').replaceWith(d3sketch(fieldVal));
           $field.val('');
           $field.focus();
         }  
    });
*/

  } );

});
  </script>

<!--end McFarland's book -->
 </head>
<body>
  
<!-- Modified McFarland Book code -->

<div id="dialog-form" title="SPARQL Endpoint">

  <form>
    <fieldset>
      <label for="name">Do your SPARQL Query here:</label>
      <input type="text" name="name" id="name" value="Jane Smith" class="text ui-widget-content ui-corner-all">
      <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
    </fieldset>
  </form>
</div>


<div class="wrapper">

  <div style="background-color:#EEEEEE" class="box a">
     <button id="create-user">SPARQL Endpoint</button> 
<!--   <input name="button" type="button" id="create-user" value="SPARQL Endpoint"> -->
   <input name="textfield" type="text" id="textfield">
   <button id="loadfileldpbutton">Load File / LDP Container</button>
<!--   <input name="button" type="button" id="button" value="Load File / LDP Container"> -->
<!--
<div style="width:100px"> --> <!-- for now this will set the width of the text field. I need to work  -->
<!--
   <input type="text" name="name" id="loadfileldptext" value="miserables.json" class="text ui-widget-content ui-corner-all"> 
</div>
-->
</div>
  <div class="box b">
    <div class="box ba">BA</div>
    <div class="box bb">BB</div>
  </div>
  <div class="box c" id="duck">
<!--
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>

// var file = "miserables.json";

//d3sketch(file);

</script>
-->

  </div>
  <div class="box d">
     <div class="box da" id="users">DA</div>
     <div class="box db">DB</div>
  </div>
</div>



</body>
</html>
 
----------------------------------------------------
 
bootstrap.js (modified from node modules folder)

---------------
 /* globals window, document */
( function() {

// Find the script element
var scripts = document.getElementsByTagName( "script" );
var script = scripts[ scripts.length - 1 ];

// Read the modules
var modules = script.getAttribute( "data-modules" );
var composite = script.getAttribute( "data-composite" ) || false;
var pathParts = window.location.pathname.split( "/" );
var effectsAll = [
 "effects/effect-blind",
 "effects/effect-bounce",
 "effects/effect-clip",
 "effects/effect-drop",
 "effects/effect-explode",
 "effects/effect-fade",
 "effects/effect-fold",
 "effects/effect-highlight",
 "effects/effect-puff",
 "effects/effect-pulsate",
 "effects/effect-scale",
 "effects/effect-shake",
 "effects/effect-size",
 "effects/effect-slide",
 "effects/effect-transfer"
];
var widgets = [
 "accordion",
 "autocomplete",
 "button",
 "checkboxradio",
 "controlgroup",
 "datepicker",
 "dialog",
 "draggable",
 "droppable",
 "menu",
 "mouse",
 "progressbar",
 "resizable",
 "selectable",
 "selectmenu",
 "slider",
 "sortable",
 "spinner",
 "tabs",
 "tooltip"
];

function getPath( module ) {
 for ( var i = 0; i < widgets.length; i++ ) {
  if ( widgets[ i ] === module ) {
   return "widgets/" + module;
  }
 }
 for ( var j = 0; j < effectsAll.length; j++ ) {
  if ( module !== "effect" ) {
   if ( effectsAll[ j ] === module ) {
    return module;
   }
   if ( effectsAll[ j ].indexOf( module ) !== -1 ) {
    return "effects/" + module;
   }
  }
 }
 return module;
}
function fixPaths( modules ) {
 for ( var i = 0; i < modules.length; i++ ) {
  modules[ i ] = getPath( modules[ i ] );
 }
 return modules;
}

// Hide the page while things are loading to prevent a FOUC
document.documentElement.className = "demo-loading";

require.config( {
 baseUrl: window.location.pathname.indexOf( "demos/" ) !== -1 ? "../../ui" : "../../../ui",
 paths: {
  jquery: "../external/jquery/jquery",
  external: "../external/",
                d3sketch: "../demos/d3sketch",
                d3: "../demos/d3.v4.min",
                isthebest: "../demos/isthebest"
             //   d3: "../../d3/build/d3"
 },
 shim: {
  "external/globalize/globalize.culture.de-DE": [ "external/globalize/globalize" ],
  "external/globalize/globalize.culture.ja-JP": [ "external/globalize/globalize" ]
 }
} );

// Replace effects all shortcut modules with all the effects modules
if ( modules && modules.indexOf( "effects-all" ) !== -1 ) {
 modules = modules.replace( /effects-all/, effectsAll.join( " " ) );
}

modules = modules ? modules.replace( /^\s+|\s+$/g, "" ).split( /\s+/ ) : [];
if ( !composite ) {
 modules.push( pathParts[ pathParts.length - 2 ] );
}
modules = fixPaths( modules );

// pull in d3sketch into the modules array so that it is available to the scripts
modules.push('d3');
modules.push('d3sketch');

require( modules, function() {
 var newScript = document.createElement( "script" );

 document.documentElement.className = "";

 newScript.text = "( function() { " + script.innerHTML + " } )();";
 document.body.appendChild( newScript ).parentNode.removeChild( newScript );
} );

} )();
 
--------------------------------------
 
 isthebest.js
 
-------------------------------------- 
define([], function () {

return function(value) {
  return value+" is great for you!";
}

});

 =================
 
modify isthebest.js to show the d3 object

+++++++++++++++++++++++++++

define(['d3'], function (d3) {

return function(value) {
  var stringcheese = JSON.stringify(d3);
  return stringcheese+value+" is great for you!";
}

});


-------------------
 
error: d3 sketch is not defined...
 

Thursday, July 20, 2017

Steps to add jquery-ui to node-arc-d3 (working draft)

$ git clone https://github.com/bshambaugh/node-arc-d3.git
$ cd node-arc-d3
$ git checkout -b btc-setup
$ npm init
$ npm install --save d3 jquery jsonld lodash n3 requirejs urijs jquery-ui
$ cd src
View the source:
$ cat index.html

Test the source in the browser:
http://localhost/bc-node-arc-d3/node-arc-d3/src/

In the browser:
http://localhost/bc-node-arc-d3/node-arc-d3/src/data/

In the data window:
http://localhost/bc-node-arc-d3/node-arc-d3/src/data/old-Food-Growing-Methods.ttl

Press the "Load File / LDP Container" Button

Edit the source:
$ vim index.html

Add right below the <body> tag:
<script src="../node_modules/jquery-ui/demos/bootstrap.js">
$("#resizable").resizable({
     handles: "se"
});
</script>

....
  <div class="box d">
     <div class="box da">DA<textarea id="resizable" rows="5" cols="20"></textarea></div>
     <div class="box db">DB</div>
  </div>
.....
// This causes the rest of the code to fail even though I do get a resizable text box







Tuesday, July 18, 2017

Getting Jupyter Server started

For Jupyter Notebook use python3 (python3 --version => 3.4), (which python3 /usr/local/bin/python3)

Install Jupyter Notebook with pip (pip3 install ---upgrade pip), (pip3 install jupyter)

Start the Jupyter server in directory where you have permissions such as $home/Documents/ (jupyter notebook)

Reference (https://jupyter.readthedocs.io/en/latest/install.html)


Set up the python packages (modules) sudo pip3 install beautifulsoup4 sudo pip3 install nltk
sudo pip3 install numpy
sudo pip3 install scipy
sudo pip3 install sklearn

Running Jupyter:

In $home/Documents: jupyter notebook

Run the script:

from bs4 import BeautifulSoup
import nltk
from nltk.corpus import stopwords
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.decomposition import TruncatedSVD

cds = open('/home/brent/Downloads/cd_catalog.xml').read()
print(cds)
soup = BeautifulSoup(cds)
postTxt = soup.findAll('artist')
postDocs = [x.text for x in postTxt]
print(postDocs)
postDocs.pop[0]   (error postDocs is not scriptable)
postDocs = [x.lower() for x in postDocs]     (changes everything to lowercase)

stopset.update(['lt','p','/p','br','amp','quot','field','front','normal','span','Opx','rgb','style','51','spacing','text','helvetica','size','family','space','arial','height','indent','letter','line','none','sans','serif','transform','line','variant','weight','times','new','strong','video','title','white','word','letter','roman','0pt','16','color','12','14','21','neue','apple','class',
               ])
 
print(postDocs)
stopset = set(stopwords.words('english'))

Sunday, July 16, 2017

Links found Looking for Latent Semantic Analysis (originally to find what Latent means)

Probabilistic Latent Semantic Analysis
http://web.mit.edu/~punk/Public/AudioExtraction/PLCApage.html

Latent Semantic Analysis
https://en.wikipedia.org/wiki/Latent_semantic_analysis

Text Analytics - Latent Semantic Analysis
https://www.youtube.com/watch?v=BJ0MnawUpaU
From Playlist:
https://www.youtube.com/watch?v=Jh1kuqm4rMc&list=PLlWzRW5RWfEX-HeTjCDWTRCOhISKrPAep

try replicating the last video with Jupyter: http://jupyter.readthedocs.io/en/latest/install.html

Friday, July 14, 2017

Links Found Looking for Linked Data and Machine Learning

"Choosing a Machine Learning Classifier" http://blog.echen.me/2011/04/27/choosing-a-machine-learning-classifier/


"3rd International Workshop on Inductive Reasoning and Machine Learning for the Semantic Web"  https://sites.google.com/site/irmles2011/


 "Volker Tresp's Homepage" http://www.dbs.ifi.lmu.de/~tresp/


Maximilian Nickel, Volker Tresp, Hans-Peter Kriegel "Factorinzing Yago" http://www.dbs.ifi.lmu.de/%7Etresp/papers/p271.pdf

(edit: see the RESCAL paper this is based on: "A Three-Way Model for Collective Learning on Multi-Relational Data"
http://www.icml-2011.org/papers/438_icmlpaper.pdf )

 Volker Tresp's student Maximilian Nickel's Homepage: http://web.mit.edu/~mnick/www/

 Maximilian Nickel's Development RESCAL: https://github.com/mnick/rescal.py

Extension EX-RESCAL: https://github.com/researchstudio-sat/webofneeds/tree/master/webofneeds/won-matcher-rescal/src/main/python/extrescal Conclusion: Factorizing Yago is useful for understanding EX-RESCAL

Wednesday, July 5, 2017

Notes for Logistic regression in R on July 5th

Steps to take for Logistic Regression in R:

(1) Load data
(2) attach(data-sample)
(3) summary(data-sample)
(4) ced.del <- cbind(sDel, sNoDel)
(5) summary(ced.del)
(6) duckie <- glm(ced.del ~ cat + follows + factor(class), family=binomial)
(7) duckie
(8) summary(duckie)
(9) anova(duckie, test="Chisq")
(10) plot(duckie)

Revised:

fico <- read.table("/home/brent/Documents/fico.csv", header=TRUE, sep=",",
  na.strings="NA", dec=".", strip.white=TRUE)

attach(fico)

duckie <- glm(approved ~ creditScore, family=binomial)

summary(duckie)

------

> summary(duckie)

Call:
glm(formula = approved ~ creditScore, family = binomial)

Deviance Residuals:
   Min      1Q  Median      3Q     Max 
-1.408  -1.338   0.959   1.010   1.149 

Coefficients:
             Estimate Std. Error z value Pr(>|z|)
(Intercept) -6.223592  17.177351  -0.362    0.717
creditScore  0.009605   0.024893   0.386    0.700

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 20.190  on 14  degrees of freedom
Residual deviance: 20.038  on 13  degrees of freedom
AIC: 24.038

Number of Fisher Scoring iterations: 4

Use the intercept and the credit score to solve for the predicted probability:
p ^ = βo + x1β1 1 + βo + x1β1

With the coefficient estimates we have:
p ^ = -6.223592 + 0.009605x1 1 + -6.223592 + 0.009605x1

Sunday, July 2, 2017

Linear Regression Notes

How to Replicate Example 10.1 in Statistics... by Mendenhall et al, 5th Ed, in R:

Y <- c(1,1,2,2,4)
X <- c(1,2,3,4,5)
fit <- lm(Y ~ X)
plot(X,Y,xlim=c(0,5),ylim=c(-1,4))
abline(fit)

> lm(Y ~ X)

Call:
lm(formula = Y ~ X)

Coefficients:
(Intercept)            X 
       -0.1          0.7

> plot(X,Y,xlim=c(0,5),ylim=c(-1,4))
> abline(fit)



> summary(fit)

Call:
lm(formula = Y ~ X)

Residuals:
         1          2          3          4          5
 4.000e-01 -3.000e-01 -6.891e-17 -7.000e-01  6.000e-01

Coefficients:
            Estimate Std. Error t value Pr(>|t|) 
(Intercept)  -0.1000     0.6351  -0.157   0.8849 
X             0.7000     0.1915   3.656   0.0354 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6055 on 3 degrees of freedom
Multiple R-squared: 0.8167,    Adjusted R-squared: 0.7556
F-statistic: 13.36 on 1 and 3 DF,  p-value: 0.03535

Link used for reference:
Using R for Linear Regression<http://www.montefiore.ulg.ac.be/~kvansteen/GBIO0009-1/ac20092010/Class8/Using%20R%20for%20linear%20regression.pdf>
<http://www.statmethods.net/advgraphs/axes.html>
<http://www.dummies.com/programming/r/how-to-add-variables-to-a-data-frame-in-r/>