code: def structure_factor_graph_model(
      tr_samples=samples, tr_labels=labels, w=w_all, ftype=ftype_all
  ):
      try:
          _ = sg.create_machine("DualLibQPBMSOSVM")
      except:
          print("DualLibQPBMSOSVM not available")
          return
  
      # create model
      model = sg.create_structured_model(
          "FactorGraphModel",
          features=tr_samples,
          labels=tr_labels,
          inf_type="TREE_MAX_PROD",
      )
      w_truth = [w[0].copy(), w[1].copy(), w[2].copy()]
      w[0] = np.zeros(8)
      w[1] = np.zeros(4)
      w[2] = np.zeros(2)
      ftype[0].set_w(w[0])
      ftype[1].set_w(w[1])
      ftype[2].set_w(w[2])
      model.add("factor_types", ftype[0])
      model.add("factor_types", ftype[1])
      model.add("factor_types", ftype[2])
  
      # --- training with BMRM ---
      bmrm = sg.create_machine(
          "DualLibQPBMSOSVM",
          model=model,
          labels=tr_labels,
          m_lambda=0.01,
      )
      # bmrm.set_verbose(True)
      bmrm.train()
      # print 'learned weights:'
      # print bmrm.get_w()
      # print 'ground truth weights:'
      # print w_truth
  
      # evaluation
      lbs_bmrm = bmrm.apply()
      acc_loss = 0.0
      ave_loss = 0.0
      print(num_samples)
      print(lbs_bmrm.get("labels")[0])
      # TODO: fix labels and expose delta_loss through new API
      # for i in range(num_samples):
      # y_pred = lbs_bmrm.get("labels")[i]
      # y_truth = tr_labels.get("labels")[i]
      # acc_loss = acc_loss + model.delta_loss(y_truth, y_pred)
      # ave_loss = acc_loss / num_samples
  
      # print('BMRM: Average training error is %.4f' % ave_loss)
  
      # show primal objs and dual objs
      # hbm = bmrm.get_helper()
      # print hbm.get_primal_values()
      # print hbm.get_eff_passes()
      # print hbm.get_train_errors()
  
      # --- training with SGD ---
      sgd = sg.create_machine(
          "StochasticSOSVM",
          model=model,
          labels=tr_labels,
          m_lambda=0.01,
      )
      # sgd.set_verbose(True)
      sgd.train()
  
      # evaluation
      # print('SGD: Average training error is %.4f' % SOSVMHelper.average_loss(sgd.get_w(), model))
      # hp = sgd.get_helper()
      # print hp.get_primal_values()
      # print hp.get_eff_passes()
      # print hp.get_train_errors()
  
      # --- training with FW ---
      fw = sg.create_machine(
          "FWSOSVM",
          model=model,
          labels=tr_labels,
          m_lambda=0.01,
          gap_threshold=0.01,
      )
      fw.train()
  
label_desc: Use image node_id 2 for calling a global function with example usage: structure_factor_graph_model(tr_samples, tr_labels, w, ftype) without return types