Bluebit Software
Bluebit Software Support Forum
 Home          Members     Calendar     Who's On

Welcome Guest ( Login | Register )
        



ActiveX Component with FOXPRO Expand / Collapse
Message
Posted Tuesday, March 21, 2006 2:22 AM Post #92
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Has anyone had any experience using this control with MS FoxPro? I have downloaded the trial version to test it out before i buy the advanced version. The excel example works but the help file says to select the activeX control from References on the Tools menu. In FoxPro there is no references option on the tools menu.

In the FoxPro options there is a 'Controls' tab where the activeX controls can be selected. I have tried to add the control to this list but it does not appear after being added.

Can anyone please give me some advice on how i go about using this control from with FoxPro?

Thanks,

James.
Posted Tuesday, March 21, 2006 4:39 AM Post #285
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
Hello,

Have a look here, I think this is what you need:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_foxhelp/html/dgextending_visual_foxpro_with_external_libraries.asp



Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 22, 2006 4:41 AM Post #288
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Thanks ive had a look at that but ive decided to go the long way around and i'm writing the fucntionality i want in VB and then calling that from foxpro. This is because you cant create a dynamic array in foxpro so i cant transfer data from the matrices to an array an vice versa if i just use fox pro.

I am planning to use your product to help me with performing principle components analysis and therefore i need the data normalized to have a mean of 0 and a standard deviation of 1. I have tried the normalize columns method with the parameter 'bmModeZScores' but this doesnt give me the correct results.

The original data values are as follows.

[6.87491 9.37361]
[0.17828 7.54182]
[3.44818 3.26085]
[3.14801 7.26423]
[7.88243 9.41093]

The values i have got from using the normalize columns method with the parameter of 3 are as follows.

[0.926 0.894]
[-1.488 0.077]
[-0.309 -1.834]
[-0.417 -0.047]
[1.289 0.911]

Mean = [0.0002 0.0002]
Standard deviation = [1.118314669 1.118129107]

The correct normalized values should be as follows.

[0.82786 0.79964]
[-1.33051 0.06847]
[-0.27660 -1.64031]
[-0.37335 -0.04233]
[1.15260 0.81454]

Mean = [0 -1.11022E-16]
Standard Deviation = [1 1]

**********************************************************

What is going wrong? Can someone help me as i cant seem to get the right values when i use this method
Posted Wednesday, March 22, 2006 5:46 AM Post #289
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
Hello,

Try this to verify the results


Dim A As New Matrix
A.Size 5, 2
A(0, 0) = 6.87491: A(0, 1) = 9.37361
A(1, 0) = 0.17828: A(1, 1) = 7.54182
A(2, 0) = 3.44818: A(2, 1) = 3.26085
A(3, 0) = 3.14801: A(3, 1) = 7.26423
A(4, 0) = 7.88243: A(4, 1) = 9.41093

'Display 6 digits
Debug.Print A.GetString(6)

A.NormalizeColumns bmModeZScores

Debug.Print A.GetString(6)

'Check to column sum
Debug.Print "ColSum 0 = " & A.ColSum(0) & " ColSum 1 =" & A.ColSum(1)

'Calculate S(x^2)/n
Debug.Print "Col 0 S(x^2)/n = " & (A.ColsDotProduct(0, 0) / A.Rows)
Debug.Print "Col 1 S(X^2)/n = " & (A.ColsDotProduct(1, 1) / A.Rows)





Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 22, 2006 6:31 AM Post #290
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Thanks ive tried it with that and i think i know where the problem is now. There are two types of standard deviation, the sample and population. This method returns the population standard deviation which is where the denominator for dividing the sum of squared deviations is simply N itself.

However i am using a sample and not a population so i need the sample standard deviation where the demoninator for dividing the sum of squared deviations is N-1.

Can this activeX control normalize the matrix in this way for me??
Posted Wednesday, March 22, 2006 6:53 AM Post #291
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support
You will have to do it using some more lines of code

First you calculate the sum using the ColSum , you get the mean by dividing by the number of rows.
Then you calculate the squares sum using ColsDotProduct, you divide by N-1 and you get samples deviation.
You update the values in a sigle step by setting x = (x-mean)/s



Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 22, 2006 7:16 AM Post #292
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
ok cool, many thanks
Posted Wednesday, March 22, 2006 7:28 AM Post #293
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
i have this at the minute

Dim M As New Matrix

M.Size 6, 3
M(0, 0) = 20.8921: M(0, 1) = 1.5012: M(0, 2) = 6.2138
M(1, 0) = 4.9635: M(1, 1) = 3.6289: M(1, 2) = 7.9978
M(2, 0) = 9.1142: M(2, 1) = 0.554: M(2, 2) = 4.2135
M(3, 0) = 11.1238: M(3, 1) = 9.8182: M(3, 2) = 9.9979
M(4, 0) = 6.1176: M(4, 1) = 5.2137: M(4, 2) = 2.4238
M(5, 0) = 13.129: M(5, 1) = 7.2285: M(5, 2) = 5.2386

Debug.Print M.GetString(4)


mean0 = M.ColSum(0) / M.Rows
mean1 = M.ColSum(1) / M.Rows
mean2 = M.ColSum(2) / M.Rows

s0 = M.ColsDotProduct(0, 0) / (M.Rows - 1)
s1 = M.ColsDotProduct(1, 1) / (M.Rows - 1)
s2 = M.ColsDotProduct(2, 2) / (M.Rows - 1)

Debug.Print M.GetString(6)

***************************************
i cant update them in one step as i have a mean for each column and a SD for each column...can i update a column at a time or do i have to use a loop to go through updating each value?
Posted Wednesday, March 22, 2006 7:55 AM Post #294
 

Bluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit SupportBluebit Support

You will have to do it element by element
You may update all columns in the same time. Something like this:


For r = 0 To M.Rows - 1
For c = 0 To M.Cols - 1
M(r, c) = (M(r, c) - mean(c)) / s(c)
Next
Next

I suggest storing the columns means and deviations in arrays




Trifon Triantafillidis

Lead Developer

Bluebit Software

Posted Wednesday, March 22, 2006 8:08 AM Post #295
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Thanks ive got that bit working now and i'm using an array. The standard deviations don't look right though.

s0 = 175.5438827
s1 = 38.312072766
s2 = 50.721087668

Ive tried using a different way rather than the colddotproduct for s0 and i stil dont seem to be getting the right values as the SD of column zero should be about 5.764762918

I'll paste my code here so you can see what i have done and hopefully where i am going wrong...

Private Sub Command3_Click()
Dim M As New Matrix
Dim mean(2) As Double
Dim sd(2) As Double

M.Size 6, 3

M(0, 0) = 20.8921: M(0, 1) = 1.5012: M(0, 2) = 6.2138
M(1, 0) = 4.9635: M(1, 1) = 3.6289: M(1, 2) = 7.9978
M(2, 0) = 9.1142: M(2, 1) = 0.554: M(2, 2) = 4.2135
M(3, 0) = 11.1238: M(3, 1) = 9.8182: M(3, 2) = 9.9979
M(4, 0) = 6.1176: M(4, 1) = 5.2137: M(4, 2) = 2.4238
M(5, 0) = 13.129: M(5, 1) = 7.2285: M(5, 2) = 5.2386

Debug.Print M.GetString(4)

mean(0) = M.ColSum(0) / M.Rows
mean(1) = M.ColSum(1) / M.Rows
mean(2) = M.ColSum(2) / M.Rows

Debug.Print "mean0 = " & mean(0)
Debug.Print "mean1 = " & mean(1)
Debug.Print "mean2 = " & mean(2)


sd(0) = M.ColsDotProduct(0, 0) / (M.Rows - 1)
sd(1) = M.ColsDotProduct(1, 1) / (M.Rows - 1)
sd(2) = M.ColsDotProduct(2, 2) / (M.Rows - 1)

s0 = 0

For x = 0 To (M.Rows - 1)
s0 = s0 + ((M(x, 0) - mean0) ^ 2)
s0 = s0 / (M.Rows - 1)
Next

Debug.Print "s0 = " & sd(0)
Debug.Print "s1 = " & sd(1)
Debug.Print "s2 = " & sd(2)


'For x = 0 To (M.Rows - 1)
' M(x, 0) = (M(x, 0) - mean0) / s0
' M(x, 1) = (M(x, 1) - mean1) / s1
' M(x, 2) = (M(x, 2) - mean2) / s2
'Next

For r = 0 To M.Rows - 1
For c = 0 To M.Cols - 1
M(r, c) = (M(r, c) - mean(c)) / sd(c)
Next
Next

Debug.Print M.GetString(6)

End Sub
Posted Wednesday, March 22, 2006 8:21 AM Post #296
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
oops i made i big mistake... ive found the errors in the above code

sd(0) = 0

For x = 0 To (M.Rows - 1)
sd(0) = sd(0) + ((M(x, 0) - mean(0)) ^ 2)
Next
sd(0) = Sqr(sd(0) / (M.Rows - 1))


its working ok now
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Trifon

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 12:09pm

Powered by InstantForum.NET v4.1.4 © 2010
Execution: 0.281. 11 queries. Compression Disabled.
.NET Matrix Library