Toward predictive interfaces: 'Google Now on tap'

In a prior post I compared “Google Now” and the concept of a Proactive User Interface. It looks like ‘Google Now on tap’ will finally be a step in the right direction.

My first impression from a quick read of some articles is that it is an expansion of the info cards concept with more correlation with current UI context. This is such a powerful, and an extremely obvious feature, that you wonder why this was not done years ago. True, Google will put more search and Big Data power behind this. But, is it really predictive and will it “learn” a users information patterns?

An information pattern example (from my prior post) is a User is viewing a web site. There is a probability that if a certain amount of time is spent or a certain page or article type is visited, that clicking a share button will be followed by predictable actions. For example, sharing a link with a colleague or loved one. The UI presented will then present a proactive plan. See “Proactive User Interface“. Generating information related to context is still requiring the user to perform wasted effort to form and act on immediate action plans. So what are those octocore chips for?

Proactive Interface v2
Diagram of idea


  • Nov 9, 2015: Google just open sourced a Machine Learning system, TensorFlow.


Fuzzy Cognitive Maps in C++

Here is some code I wrote to compute FCM. I used this while learning about Fuzzy Systems. Just posted here for storage.

FCM is one of the technologies in field of Soft Computing.

// *************************************************************************
// File:  FCM2.H  ver. 0.03   Date:  September 25, 1993
// By:    Josef Betancourt    System:  Borland C++ ver. 2.0.
// *************************************************************************
Purpose:  Illustrate the Fuzzy Cognitive Map computations.

This is a very very simple implementation of the FCM example found in:
"Neural Networks and Fuzzy Systems". Kosko, B. page 154.
"Fuzzy Thinking, the new science of fuzzy logic". Kosko, B. page 222.
"Fuzzy Logic". McNeill D., Freiberger, P. page 237.

I used a very nice matrix class called Beginner's Understandable Matrix Package, 
BUMP.ZIP, by Clopper Almon. It is found in the Borland C++ forum on CIS. 

This version of my FCM implementation allows the setting of more than one
policy variable in the policy vector.  This is accomplished by loading
a state setting i by 2 matrix.  If column one is zero than cell i in the
policy vector is not reset by the state vector, else during the reasoning
process that cell is reset to the value in column two.

 Of course, a general purpose interactive graphical system where the FCM
 can be entered graphically by multiple experts and the inference process
 is visually presented would be nice.  It should be a FCM CAD system!
 But are FCMs really useful?  How are they used in control systems?

USE:  This must be compiled and linked with BUMP.CPP. Large memory model.

        Example       FCM file       Policy        State
      Africa         AFRICA.TXT     INVEST.TXT    INVEST2.TXT
      Africa         AFRICA.TXT     DIVEST.TXT    DIVEST2.TXT

    To test the africa example,
    Use the syntax:  FCM africa.txt invest.txt invest2.txt 9 .5
    or               FCM africa.txt divest.txt divest2.txt 9 .5

    To test the cocaine example in the book Fuzzy Thinking,
    Use the syntax: FCM cocaine.txt interdic.txt interdi2.txt 11 .5
    ( this example does not result in cocaine supply falling as stated in
    the book.)
#ifndef FCM2_H
#define FCM2_H

// -----------------------
// dependencies
#include <iostream.h>   // for cout
#include <ctype.h>      // for isdigit()
#include <stdio.h>      // for fgets()
#include <alloc.h>      // for coreleft()
#include <stdlib.h>     // for atof()
#include <conio.h>      // for cprintf()
#include "bump.h"       // for Matrix class
// -----------------------

#define TRUE (1==1)
#define FALSE (!TRUE)

class FCM;  // forward reference.

// Prototypes
void Reason( FCM &fcm);
void Again(void);
void ThresholdMF( Matrix & mat, float thresh = .5);
void ConvertMat( Matrix & matDest, Matrix &matSrc);
void ResetPolicy( Matrix & matDest, Matrix &matSrc);
void ShowCondenseMP( Matrix &Mat);
void DrawBorder(void);

class FCM{  // Fuzzy Cognitive Map
        Matrix *pmatFCM;    // directed graph.
        Matrix *pmatPolicy; // initial policy.
        Matrix *pmatState;  // policies to reset after epoch.
        char *Names[];      // the labels of each node.
        int   nPolicies;     // number of nodes.
        float fThreshold;
        FCM( int n);  // constructor.
        // FCM( FCM other); // copy constructor.
        // ~FCM(); // destructor.
        void  SetSizeI( int size){ nPolicies = size;}
        void  SetThresh( float fthr){ fThreshold = fthr; }
        int   IGetSize( void){ return nPolicies;}
        void  SetFCM( Matrix *fcm){ pmatFCM = fcm;}
        void  SetPolicy( Matrix *Policy){ pmatPolicy = Policy;}
        void  SetState( Matrix *State){ pmatState = State; }
        void  ReadFCM( char *psz);
        float &Cell( Matrix *pmat, int i, int j);
        float GetCell( Matrix *pmat, int i, int j);
        void  ReasonStep( void);
        void  ThresholdMF(void);
        void  ResetPolicy( void );
        void  DisplayPolicy( char *msg);
        Matrix &WhatIsPolicy( void){  return *pmatPolicy ; }
        void  DumpPolicy(void);

// end of file FCM2.H

// *************************************************************************
// File:  FCM2.CPP  ver. 0.03               Date:  September 25, 1993
// By:  Josef Betancourt    System:  Borland C++ 4.0
// *************************************************************************
Purpose:  Illustrate the Fuzzy Cognitive Map computations.

// dependencies....

#include "fcm2.h"

// -----------------------------------------
//  constructor.
FCM::FCM( int size){
    SetSizeI(size );
    fThreshold = .5;
// -----------------------------------------
// get address of Cell.
float &FCM::Cell( Matrix *pmat, int i, int j){
    return pmat->operator[](i)[j];
// -----------------------------------------
// get cell contents.
float FCM::GetCell( Matrix *pmat, int i, int j){
    return pmat->operator[](i)[j];
// -----------------------------------------
void FCM::ReasonStep( void){
   // Matrix multiply.  Nice syntax!
    *pmatPolicy = (*pmatPolicy)*(*pmatFCM);
   //DisplayPolicy( "policy after multiply: ");

   //DisplayPolicy( "policy after threshold: ");

   //DisplayPolicy( "policy after reset: ");
// -----------------------------------------
// threshold policy vector.
void FCM::ThresholdMF( void ){
    // apply thresh to policy matrix, default thresh is 0.5.
    for( int i = 1; i < nPolicies + 1; i++){
        if( GetCell( pmatPolicy, 1, i) >= fThreshold ){
            Cell(pmatPolicy, 1, i) = 1.;
            Cell( pmatPolicy, 1, i) = 0;
// -----------------------------------------
// reset policy with state vector.
void FCM::ResetPolicy( void ){
    for( int i = 1; i < nPolicies+1; i++){
        if( GetCell( pmatState, i,1) == 1){
            Cell( pmatPolicy, 1, i) = GetCell(pmatState, i, 2) ;
// -----------------------------------------
// show policy using matrix library display routine.
void FCM::DisplayPolicy( char *message){
// -----------------------------------------
// dump policy as simple number dump.
void FCM::DumpPolicy(void){
    for( int i=1; i < nPolicies+1; i++){
        cout << GetCell( pmatPolicy, 1, i);
// -----------------------
int main(int argc, char * argv[]){
    cout << "\n*** Fuzzy Cognitive Map example.  By Josef Betancourt ***\n";
    if( argc != 6 ){
     cerr << "\nUsage: fcm <FCM file> <policy file> <state file>";
     cerr << "<matrix size> <thresh>\n";
     cerr << "         Where cell and value refer to policy vector.\n";
     exit (-1);
    // convert strings to integers...........
    int iSize = atoi(argv[4]); // matrix order.
    float fThresh = atof( argv[5]); // threshold value.

    FCM theFCM( iSize);

   // create the helper matrices.
    Matrix matFCM(iSize,iSize), matPolicy(1, iSize),
            matVPolicy(1,iSize), matState( iSize, 2);

   // link them into the FCM
    theFCM.SetFCM( &matFCM);
    theFCM.SetPolicy( &matPolicy);
    theFCM.SetState( &matState);
    theFCM.SetThresh( fThresh);

    // populate using files
    matFCM.ReadA( argv[1] );
    matPolicy.ReadA( argv[2] );
    matState.ReadA( argv[3] );

   // and show matrices ..........
    matFCM.Display("This is the FCM matrix:");
    matPolicy.Display("This is the policy matrix: ");
   matState.Display("This is the state matrix: ");

    cout << "test of dump\n" ;

    Again();    // wait for key tap or escape.

   // perform the FCM process using the object.
    Reason(theFCM );

    return FALSE;
}  // end of main.
// -----------------------
void Reason( FCM &fcm ){
    // apply simple FCM computation using matrices.
    int i = 1;  // epoch counter.
    while( 1){
        cout << "Epoch " << i << '\n';
        fcm.DisplayPolicy("New policy vector: ");

      // for ease in seeing limit cycles.
        ShowCondenseMP( fcm.WhatIsPolicy() );

        Again();   // wait for key tap or escape.
} // reason end.
// -----------------------
void ShowCondenseMP( Matrix &Mat){
    // print policy vector in a more visual pattern.
    cout << "\nPattern: ";
    char temp ;
    for( int i=1; i< Mat.columns()+1; i++){
        if( Mat[1][i] > 0 ){
            temp = 0x2;
            if( Mat[1][i] < 0){
                temp = 0x1F;
                temp = 0x1;
        cout.put( temp);
    cout << '\n' ;
// -----------------------
void DrawBorder(void){
    cout << '\n';
    for( int i=0; i<75; i++){
        cout.put( char(0xDF) );
    cout << '\n';
// -----------------------
void Again(void){
    // query user for continuation or end of run.
    cerr << "\n\t\t\t< Tap a key to continue.  ESC to exit. >\n";
    if(getch() == 27){
// ----------------------------------------------------------------------
/*  computing Eigenvectors is similar to computing a FCM without the
     thresholding.  Here is such an algorithm.

void EigenTest(int size, char *pszName){
    // algorithim from Computational Linear Algebra with Models.
    // Williams, Gareth.  Allyn and Bacon, Massachusetts. 1978. page 449.
     float e, s, t;
     int i, j, k, M;
     Matrix A(size,size), X(size,1),Y(size,1),Z(size,1);
     A.Display("Here is the B matrix:");
     AllOnes( X);
        cout << "Iteration " << i << "\n";
        Y = A * X;
        Y.Display("Here is the Y matrix:");
        for( j=2; j < Y.rows()+1;j++){
            if( fabs( Y[k][1]) >= fabs( Y[j][1]) ){
            k= j;
        Y = ( 1/ fabs( Y[k][1])) * Y;
        X = Y;
        X.Display("the adjusted vector is:");
        Z = A*X;
        for( M=1; M<size + 1; M++){
            s += X[M][1] * Z[M][1];
            t += X[M][1] * X[M][1];
        e = s/t;
        cout << "Approx eigenvalue is " << e << "\n" ;
// -----------------------
// End of file FCM.CPP *********************************

Off topic
There are a lot of examples of connectionist presentations. I wonder if these could be coupled with the FCM technique to create computable structures. For example, look at the work of Mark Lombardi.


Google Now and predictive interfaces

In a prior post, Proactive User Interface, I was following up on prior thoughts I’ve had on digital assistants. Like with this other post: Synergistic Social Agent Network Cloud, or A Fuzzy Logic Controller Using Fuzzy Feedback.

Now I’ve just tried Google Now. (This current blog post was written a while back) Wow, I had that idea. I called “cards” Proposals. But, I think my concept is more advanced. In fact, without more advanced Artificial Intelligence advances, a true Assistant is not possible. This concept, of course, is not new. Shows up very early in Science Fiction literature.