Click to show TOC

Introduction

This is a slightly more elaborate example

Code example

This is a simple code example to create a javascript array and display it.

 
 
     

What just happened, if you execute the code above it will display the array just created.

Note: the last expression array is displayed.

Some simple notes

  • You can edit the example above and runit as may time as you want
  • The code changes its theme once you edit it to show you A variable created within a !tryit snippet usin a let only exists in the snipped




Page - 1




Another Page

This is one more example in a new page. The is it my test.

This is a example of optimization useful in certain modeling of estimating the cost of service for medical conditions. One simple model for a service, for example heart contition, is as follows:

  1. Average base cost
  2. Number of additional complications that increase the cost of treatment. Example of thos those may be age, if you are older or very young. A simple model is to assume that each condition increases the cost by a certain percent. a. Cost = Base * comp1 * comp2 * comp3, where comp1, comp2 percentage increase on the base cost. b. This can also be written in exponential form Cost = exp( b + c1 + c2 + c3 ) where b = ln(Base), and c1 = ln(comp1)
  3. The values of b, c1, c2… (also refered to as cost factors) are unknown, but we have data for the cost of service fr thousands of patients. We will use the date to extimate the values of the cost factors.
  4. This becomes a regression problem

Some utility functions

  1. expL take the exponent of the elements of an array
  2. rect acts like a rectifier in electronic circuit if val is negetive return 0, otherwise return the value, clamp id similar, returns 0 for negetive values and 1 for positive calues
  3. max returns the max value of a list
  4. stdPdiv get standard deviation uning only the poisitve values of an array
  5. range Create a array with elemenst [0, 1, 2, … n-1]
  6. zip Takes 2 lists (list1, list2) and returns a new array with length of list1, where element i is a 2 element array [ list1[i], list2[i] ]
 
 
     

Object to model the cost of treatment, this has the following attributes

  1. real the actual cost of treatment
  2. factorFlag this is an array of 1 or 0 for each of the cost factors 1 = factor present for the patient, 0 = factor not present
  3. real holds the real cost. Since we do not actually have real data we will create some simulated data, a. All patients have the base factor b codes[0] b. The other factors have arelative probability of occuring, code[1] has (100-70) = 30% chance, codes[2] has (100-90)= 10% chance and so on, this is allocodea using fillFactor() function.
  4. current best estimate of cost prediction based on the factors estimates
 
 
     

Setup some constants

  1. EPI_COUNT - number of test episodes to create
  2. ITER - number of itteratins to compute the factors
  3. EPSILON - increment size for the gradient descent
 
 
     
 
 
     

some space to inspect data

 
 
     
 
 
     

Display debug

 
 
     




Page - 2




Fast risk factor

This is a more optimized risk factor calculator usin the log(e(x)) = log(Total) property. This linearizes the problem.

 
 
     
 
 
     




Page - 3




Factor based optimization

This section we will show how the multiplicative concept of optimization can be used compute the gradient descent algorithm

 
 
     



Page - 4